def swap(arr, i, j): temp = arr[i] arr[i] = arr[j] arr[j] = temp def part(arr, beg, end): : return beg v = arr[beg] idx = beg + , end+): if(arr[x] < v): swap(arr, idx, x) idx += swap(arr, idx-, beg) def sort(arr, beg, end): : return i = part(arr, beg…