Quick-sort
Explore the Quick-sort algorithm, focusing on its recursive approach and the partitioning technique by Lomuto. Understand how to choose pivots, partition arrays, and analyze the algorithm's correctness and time complexity. This lesson helps you implement and apply Quick-sort effectively in Java.
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 work is splitting the array into smaller subarrays before recursion so that merging the sorted subarrays is trivial.
- Choose a pivot element from the array.
- Partition the array into three subarrays 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 we’re presenting here is attributed to Nico Lomuto. The variable counts the number of items in the array that are less than the pivot element.
Algorithm
...