The document discusses quicksort algorithms and provides pseudocode to sort a list of numbers. It shows the steps of choosing a pivot element, comparing elements on the left and right of the pivot, swapping elements if out of order, and recursively applying the process to subarrays until the full list is sorted. An example sort of the list [5, 3, 1, 9, 8, 2, 4, 7] is provided to demonstrate how the pivot element is used to partition the list into sorted left and right subarrays at each step.
5. 5 3 1 9 8 2 4 7
left right
pivot
Sorting list of Numbers
[5, 3, 1, 9, 8, 2, 4, 7]
6. 5 3 1 9 8 2 4 7
left right
pivot
Comparing left with right and sort
small numbers at the left
Here, the left and right
are already sorted
7. 5 3 1 9 8 2 4 7
left right
pivot
Algorithm moves forward one
position towards left
8. 5 3 1 9 8 2 4 7
left right
pivot
Doing the same thing to compare left with
right and sort small numbers at the left
Here, the left and
right are not sorted
9. 4 3 1 9 8 2 5 7
right
left
pivot
So, we swap value in the left
with its in the right
And the pivot stays
points at the same value
10. 4 3 1 9 8 2 5 7
right
left
pivot
And then left will move to
the next index
11. 4 3 1 9 8 2 5 7
right
left
pivot
Then, we repeat the same steps with each
element to get left, right and pivot at the
same index. Hence, the element is sorted
12. 4 3 1 2 5 8 9 7
right
left
pivot
Here, (5) is sorted. And we surely know that
elements on its left is smaller than its right
13. 1 2 3 4 5 7 8 9
right
left
pivot
We do the same thing recursively to the two
left and right sub array of the pivot element
until we get the list sorted as seen;