No. of comparisons: 0 No. of swaps: 0
function partition(left,
right)
pivot = right
i = left
j = right - 1
while(i < j)
while(i <
right && list[i] < pivot)
i += 1
while(j >
left && list[j] > pivot)
j -= 1
if(i <
j)
swap(list[i], list[j])
if(list[i] >
list[pivot])
swap(list[i], list[pivot])
return i
function quicksort(left,
right)
if(left < right)
p =
partition(left, right)
quicksort(left, p - 1)
quicksort(p
+ 1, right)
---------------------
| SHORT EXPLANATION |
---------------------
1. Pick the last element as pivot
2. Reorder the array in the following way:
- All elements less than the pivot come before the
pivot
- All elements greater than the pivot come after the
pivot
3. Recursively apply the above steps to each sublist