Step 2: Once we get the pivot element, then we create 2 half such that, the elements left to the pivot element are lesser than pivot element.
In this example, we shall select the lowest element as pivot element.
By doing the above 2 operations, we make sure that all the elements to the left of pivot element are less and elements to right of pivot are greater.
Implementation of Quick Sort in C
In the worst case, the time taken will be O(n^2).
Steps to select pivot element.
we swap the elements in their respective positions.
Similarly, while comparing with the right pointer, we check if the element is greater than the pivot element. If the element is less than the pivot element, we swap the elements.