skip to main content
research-article

How Good Is Multi-Pivot Quicksort?

Published: 10 October 2016 Publication History

Abstract

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 by Yaroslavskiy, Bentley, and Bloch was chosen as the standard sorting algorithm in Sun’s Java 7. In 2014 at ALENEX, Kushagra et al. introduced an even faster algorithm that uses three pivots. This article studies what possible advantages multi-pivot quicksort might offer in general. The contributions are as follows: Natural comparison-optimal algorithms for multi-pivot quicksort are devised and analyzed. The analysis shows that the benefits of using multiple pivots with respect to the average comparison count are marginal and these strategies are inferior to simpler strategies such as the well-known median-of-k approach. A substantial part of the partitioning cost is caused by rearranging elements. A rigorous analysis of an algorithm for rearranging elements in the partitioning step is carried out, observing mainly how often array cells are accessed during partitioning. The algorithm behaves best if three to five pivots are used. Experiments show that this translates into good cache behavior and is closest to predicting observed running times of multi-pivot quicksort algorithms. Finally, it is studied how choosing pivots from a sample affects sorting cost. The study is theoretical in the sense that although the findings motivate design recommendations for multipivot quicksort algorithms that lead to running-time improvements over known algorithms in an experimental setting, these improvements are small.

References

[1]
Martin Aumüller and Martin Dietzfelbinger. 2013. Optimal partitioning for dual pivot quicksort. In Proceedings of the 40th International Colloquium on Automata, Languages and Programming (ICALP’13). Springer, 33--44.
[2]
Martin Aumüller and Martin Dietzfelbinger. 2015. Optimal partitioning for dual-pivot quicksort. ACM Trans. Algor. 12, 2 (2015), 18.
[3]
Martin Aumüller, Martin Dietzfelbinger, Clemens Heuberger, Daniel Krenn, and Helmut Prodinger. 2016. Counting zeros in random walks on the integers and analysis of optimal dual-pivot quicksort. CoRR abs/1602.04031 (2016), In Proceedings of the 27th International Conference on Probabilistic, Combinatorial and Asymptotic Methods for the Analysis of Algorithms (AofA'16), 3.
[4]
Martin Aumüller. 2015. On the Analysis of Two Fundamental Randomized Algorithms: Multi-Pivot Quicksort and Efficient Hash Functions. Ph.D. Dissertation. Technische Universität Ilmenau.
[5]
Jon L. Bentley and M. Douglas McIlroy. 1993. Engineering a sort function. Softw. Pract. Exp. 23, 11, 1249--1265.
[6]
Jon Louis Bentley and Robert Sedgewick. 1997. Fast algorithms for sorting and searching strings. In Proceedings of the 8th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA’97). ACM, 360--369.
[7]
Joshua Bloch. 2015. Personal Communication.
[8]
Edsger W. Dijkstra. 1976. A Discipline of Programming. Prentice-Hall.
[9]
Devdatt P. Dubhashi and Alessandro Panconesi. 2009. Concentration of Measure for the Analysis of Randomized Algorithms. Cambridge University Press.
[10]
Stefan Edelkamp and Armin Weiss. 2016. BlockQuicksort: Avoiding branch mispredictions in quicksort. In Proceedings of the 24th Annual European Symposium on Algorithms (ESA'16). 38:1--38:16.
[11]
Amr Elmasry, Jyrki Katajainen, and Max Stenmark. 2012. Branch mispredictions don’t affect mergesort. In Proceedings of the 11th International Symposium on Experimental Algorithms (SEA’12). 160--171.
[12]
Agner Fog. 2014. 4. Instruction tables. Retrieved from http://www.agner.org/optimize/instruction_tables.pdf.
[13]
W. D. Frazer and A. C. McKellar. 1970. Samplesort: A sampling approach to minimal storage tree sorting. J. ACM 17, 3, 496--507.
[14]
Adriano M. Garsia and Michelle L. Wachs. 1977. A new algorithm for minimum cost binary trees. SIAM J. Comput. 6, 4, 622--642.
[15]
Ronald L. Graham, Donald E. Knuth, and Oren Patashnik. 1994. Concrete Mathematics—A Foundation for Computer Science, 2nd ed. Addison-Wesley.
[16]
Pascal Hennequin. 1991. Analyse en Moyenne D’algorithmes: Tri Rapide et Arbres de Recherche. Ph.D. Dissertation. Ecole Politechnique, Palaiseau.
[17]
C. A. R. Hoare. 1962. Quicksort. Comput. J. 5, 1 (1962), 10--15.
[18]
T. C. Hu and A. C. Tucker. 1971. Optimal computer search trees and variable-length alphabetical codes. SIAM J. Appl. Math. 21, 4, 514--532.
[19]
Vasileios Iliopoulos. 2014. A note on multipivot quicksort. CoRR abs/1407.7459.
[20]
Kanela Kaligosi and Peter Sanders. 2006. How branch mispredictions affect quicksort. In Proceedings of the 14th Annual European Symposium on Algorithms (ESA’06). Springer, 780--791.
[21]
Donald E. Knuth. 1973. The Art of Computer Programming, Volume III: Sorting and Searching. Addison-Wesley.
[22]
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.
[23]
Anthony LaMarca and Richard E. Ladner. 1999. The influence of caches on the performance of sorting. J. Algor. 31, 1 (1999), 66--104.
[24]
Nikolaj Leischner, Vitaly Osipov, and Peter Sanders. 2010. GPU sample sort. In Proceedings of the 24th IEEE International Symposium on Parallel and Distributed Processing, IPDPS 2010, Atlanta, Georgia, USA, 19--23 April 2010. 1--10.
[25]
David Levinthal. 2009. Performance Analysis Guide for Intel Core i7 Processor and Intel Xeon 5500 processors. Retrieved from https://software.intel.com/sites/products/collateral/hpc/vtune/performance_analysis_guide.pdf.
[26]
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.
[27]
Conrado Martínez and Salvador Roura. 2001. Optimal sampling strategies in quicksort and quickselect. SIAM J. Comput. 31, 3 (2001), 683--705.
[28]
Peter M. McIlroy, Keith Bostic, and M. Douglas McIlroy. 1993. Engineering radix sort. Comput. Syst. 6, 1 (1993), 5--27.
[29]
Markus E. Nebel, Sebastian Wild, and Conrado Martínez. 2016. Analysis of pivot sampling in dual-pivot quicksort: A holistic analysis of Yaroslavskiy’s partitioning scheme. Algorithmica 75, 4 (2016), 632--683.
[30]
Naila Rahman. 2002. Algorithms for hardware caches and TLB. In Algorithms for Memory Hierarchies, Advanced Lectures {Dagstuhl Research Seminar, March 10--14, 2002}. 171--192.
[31]
Salvador Roura. 2001. Improved master theorems for divide-and-conquer recurrences. J. ACM 48, 2 (2001), 170--205.
[32]
Peter Sanders and Sebastian Winkel. 2004. Super scalar sample sort. In Proceedings of the 12th Annual European Symposium on Algorithms (ESA’04). Springer, 784--796.
[33]
Robert Sedgewick. 1975. Quicksort. Ph.D. Dissertation. Standford University.
[34]
Robert Sedgewick. 1977. Quicksort with equal keys. SIAM J. Comput. 6, 2 (1977), 240--268.
[35]
Kok-Hooi Tan. 1993. An Asymptotic Analysis of the Number of Comparisons in Multipartition Quicksort. Ph.D. Dissertation. Carnegie Mellon University.
[36]
M. H. van Emden. 1970. Increasing the efficiency of quicksort. Commun. ACM 13, 9 (Sept. 1970), 563--567.
[37]
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.
[38]
Sebastian Wild, Markus E. Nebel, and Ralph Neininger. 2015. Average case and distributional analysis of dual-pivot quicksort. ACM Trans. Algor. 11, 3 (2015), 22.
[39]
Vladimir Yaroslavskiy. 2009. Replacement of Quicksort in java.util.Arrays with new Dual-Pivot Quicksort (Thread). Retrieved from http://osdir.com/ml/java-openjdk-core-libs-devel/2009-09/msg00160.html.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Algorithms
ACM Transactions on Algorithms  Volume 13, Issue 1
January 2017
422 pages
ISSN:1549-6325
EISSN:1549-6333
DOI:10.1145/2997037
Issue’s Table of Contents
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 10 October 2016
Accepted: 01 June 2016
Revised: 01 May 2016
Received: 01 October 2015
Published in TALG Volume 13, Issue 1

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Sorting
  2. multi-pivot
  3. quicksort

Qualifiers

  • Research-article
  • Research
  • Refereed

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)43
  • Downloads (Last 6 weeks)6
Reflects downloads up to 09 Feb 2025

Other Metrics

Citations

Cited By

View all

View Options

Login options

Full Access

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media