Example of Quick Sort
Array of 7 elements (8, 7, 6, 1, 0, 9, 2)
In different variations of quicksort, the pivot element is selected from different positions. Here, we will select the rightmost element of the array as the pivot element.
.png)
Rearranging the Array: Put all the smaller elements on the left and greater on the right of pivot element.
- Comparison of pivot element with element beginning from the first index
.png)
- If the element is greater than the pivot element, a second pointer is set for that element.
.png)
- Pivot is compared with other elements.
.png)
- The process is repeated to set the next greater element as the second pointer.
.png)
- The process goes on until the second last element is reached.
.png)
- Finally, the pivot element is swapped with the second pointer.
.png)
- Pivot Elements are chosen again for left and right sub-parts. So, final sorted array is as follows.
.png)
8
