Abstract
Dual-pivot quicksort refers to variants of classical quicksort where in the partitioning step two pivots are used to split the input into three segments. This can be done in different ways, giving rise to different algorithms. Recently, a dual-pivot algorithm due to Yaroslavskiy received much attention, because it replaced the well-engineered quicksort algorithm in Oracle’s Java 7 runtime library. Nebel and Wild (ESA 2012) analyzed this algorithm and showed that on average it uses 1.9nln n + O(n) comparisons to sort an input of size n, beating standard quicksort, which uses 2nln n + O(n) comparisons. We introduce a model that captures all dual-pivot algorithms, give a unified analysis, and identify new dual-pivot algorithms that minimize the average number of key comparisons among all possible algorithms up to a linear term. This minimum is 1.8nln n + O(n). For the case that the pivots are chosen from a small sample, we include a comparison of dual-pivot quicksort and classical quicksort. Specifically, we show that dual-pivot quicksort benefits from a skewed choice of pivots. We experimentally evaluate our algorithms and compare them to Yaroslavskiy’s algorithm and the recently described 3-pivot quicksort algorithm of Kushagra et al. (ALENEX 2014).
- Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. 2009. Introduction to Algorithms (3rd ed.). MIT Press. Google ScholarDigital Library
- Devdatt P. Dubhashi and Alessandro Panconesi. 2009. Concentration of Measure for the Analysis of Randomized Algorithms. Cambridge University Press. Google ScholarDigital Library
- Pascal Hennequin. 1991. Analyse en moyenne d’algorithmes: tri rapide et arbres de recherche. Ph.D. Dissertation. Ecole Politechnique, Palaiseau. http://www-lor.int-evry.fr/∼pascal/.Google Scholar
- C. A. R. Hoare. 1962. Quicksort. Computer Journal 5, 1 (1962), 10--15.Google ScholarCross Ref
- Donald E. Knuth. 1973. The Art of Computer Programming, Volume III: Sorting and Searching. Addison-Wesley.Google Scholar
- Shrinu Kushagra, Alejandro López-Ortiz, Aurick Qiao, and J. Ian Munro. 2014. Multi-pivot quicksort: Theory and experiments. In Proceedings of the 16th Meeting on Algorithms Engineering and Experiments (ALENEX’14). SIAM, 47--60. Google ScholarDigital Library
- Conrado Martínez, Markus E. Nebel, and Sebastian Wild. 2015. Analysis of branch misses in quicksort. In Proceedings of the 12th Meeting on Analytic Algorithmics and Combinatorics (ANALCO’15). 114--128. Google ScholarDigital Library
- Conrado Martínez and Salvador Roura. 2001. Optimal sampling strategies in quicksort and quickselect. SIAM Journal on Computing 31, 3 (2001), 683--705. Google ScholarDigital Library
- Salvador Roura. 2001. Improved master theorems for divide-and-conquer recurrences. Journal of the ACM 48, 2 (2001), 170--205. Google ScholarDigital Library
- Robert Sedgewick. 1975. Quicksort. Ph.D. Dissertation. Standford University.Google Scholar
- Robert Sedgewick. 1977. Quicksort with equal keys. SIAM J. Comput. 6, 2 (1977), 240--268.Google ScholarCross Ref
- Robert Sedgewick and Philippe Flajolet. 1996. An Introduction to the Analysis of Algorithms. Addison-Wesley-Longman. Google ScholarDigital Library
- M. H. van Emden. 1970. Increasing the efficiency of quicksort. Communications of the ACM 13, 9 (1970), 563--567. Google ScholarDigital Library
- Sebastian Wild. 2013. Java 7’s Dual Pivot Quicksort. Master’s thesis. University of Kaiserslautern.Google Scholar
- Sebastian Wild and Markus E. Nebel. 2012. Average case analysis of Java 7’s dual pivot quicksort. In Proceedings of the 20th European Symposium on Algorithms (ESA’12). 825--836. Google ScholarDigital Library
- Sebastian Wild, Markus E. Nebel, and Conrado Martínez. 2014. Analysis of pivot sampling in dual-pivot quicksort. CoRR abs/1412.0193 (2014).Google Scholar
- Sebastian Wild, Markus E. Nebel, and Ralph Neininger. 2015. Average case and distributional analysis of dual-pivot quicksort. ACM Transactions on Algorithms 11, 3 (2015), 22. Google ScholarDigital Library
- Sebastian Wild, Markus E. Nebel, Raphael Reitzig, and Ulrich Laube. 2013. Engineering Java 7’s dual pivot quicksort using MaLiJAn. In Proceedings of the 15th Meeting on Algorithms Engineering and Experiments (ALENEX’13). 55--69. Google ScholarDigital Library
Index Terms
- Optimal Partitioning for Dual-Pivot Quicksort
Recommendations
How Good Is Multi-Pivot Quicksort?
Multi-Pivot Quicksort refers to variants of classical quicksort where in the partitioning step k pivots are used to split the input into k + 1 segments. For many years, multi-pivot quicksort was regarded as impractical, but in 2009 a two-pivot approach ...
GPU-Quicksort: A practical Quicksort algorithm for graphics processors
In this article, we describe GPU-Quicksort, an efficient Quicksort algorithm suitable for highly parallel multicore graphics processors. Quicksort has previously been considered an inefficient sorting solution for graphics processors, but we show that ...
Analysis of Pivot Sampling in Dual-Pivot Quicksort: A Holistic Analysis of Yaroslavskiy's Partitioning Scheme
The new dual-pivot Quicksort by Vladimir Yaroslavskiy--used in Oracle's Java runtime library since version 7--features intriguing asymmetries. They make a basic variant of this algorithm use less comparisons than classic single-pivot Quicksort. In this ...
Comments