Quick-sort
Get to know about the Quick-sort algorithm and how it uses recursion to sort elements.
We'll cover the following...
Quick-sort algorithm and its partitioning technique
Quick-sort is another recursive sorting algorithm, discovered by Tony Hoare in 1959 and first published in 1961. In this algorithm, the hard part is splitting the array into smaller subarrays before recursion so that merging the sorted subarrays is trivial. It follows these steps:
- Choose a pivot element from the array.
- Partition the array into three subarrays respectively containing the elements smaller than the pivot, the pivot element itself, and the elements larger than the pivot.
- Recursively quick-sort the first and last subarrays.
A more detailed pseudocode is given below. In the subroutine, the input parameter is the index of the pivot element in the unsorted array; the subroutine partitions the array and returns the new index of the pivot element. There are many different efficient partitioning algorithms; the one presented here is attributed to Nico Lomuto. The variable counts the number of items in the array that are less than the pivot element.
Algorithm
...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy