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 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.

[1]  Martin Aumüller,et al.  On the Analysis of Two Fundamental Randomized Algorithms - Multi-Pivot Quicksort and Efficient Hash Functions , 2015 .

[2]  Martin Dietzfelbinger,et al.  Optimal Partitioning for Dual-Pivot Quicksort , 2013, ICALP.

[3]  T. C. Hu,et al.  Optimal Computer Search Trees and Variable-Length Alphabetical Codes , 1971 .

[4]  Robert Sedgewick,et al.  Fast algorithms for sorting and searching strings , 1997, SODA '97.

[5]  Sebastian Wild,et al.  Average Case Analysis of Java 7's Dual Pivot Quicksort , 2012, ESA.

[6]  Martin Dietzfelbinger,et al.  Optimal Partitioning for Dual-Pivot Quicksort , 2013, ACM Trans. Algorithms.

[7]  Adriano M. Garsia,et al.  A New Algorithm for Minimum Cost Binary Trees , 1977, SIAM J. Comput..

[8]  Sebastian Wild,et al.  Analysis of Branch Misses in Quicksort , 2015, ANALCO.

[9]  Amr Elmasry,et al.  Branch Mispredictions Don't Affect Mergesort , 2012, SEA.

[10]  Bob Sedgewick,et al.  Multi-Pivot Quicksort : Theory and Experiments , 2014 .

[11]  Vitaly Osipov,et al.  GPU sample sort , 2010, 2010 IEEE International Symposium on Parallel & Distributed Processing (IPDPS).

[12]  Vasileios Iliopoulos A note on multipivot Quicksort , 2014, ArXiv.

[13]  Sebastian Winkel,et al.  Super Scalar Sample Sort , 2004, ESA.

[14]  Ronald L. Graham,et al.  Concrete mathematics - a foundation for computer science , 1991 .

[15]  Sebastian Wild,et al.  Average Case and Distributional Analysis of Dual-Pivot Quicksort , 2013, ACM Trans. Algorithms.

[16]  Kurt Mehlhorn,et al.  On a Model of Virtual Address Translation , 2015, ACM J. Exp. Algorithmics.

[17]  Stefan Edelkamp,et al.  BlockQuicksort: How Branch Mispredictions don't affect Quicksort , 2016, ArXiv.

[18]  Jon Louis Bentley,et al.  Engineering a sort function , 1993, Softw. Pract. Exp..

[19]  Richard E. Ladner,et al.  The influence of caches on the performance of sorting , 1997, SODA '97.

[20]  M. H. van Emden Increasing the efficiency of quicksort , 1970, CACM.

[21]  Ronald L. Graham,et al.  Concrete mathematics - a foundation for computer science (2. ed.) , 1994 .

[22]  C. SIAMJ. OPTIMAL SAMPLING STRATEGIES IN QUICKSORT AND QUICKSELECT , 2001 .

[23]  Edsger W. Dijkstra,et al.  A Discipline of Programming , 1976 .

[24]  Helmut Prodinger,et al.  Counting Zeros in Random Walks on the Integers and Analysis of Optimal Dual-Pivot Quicksort , 2016, ArXiv.

[25]  Markus E. Nebel,et al.  Analysis of Pivot Sampling in Dual-Pivot Quicksort: A Holistic Analysis of Yaroslavskiy’s Partitioning Scheme , 2014, Algorithmica.

[26]  Conrado Martínez,et al.  Optimal Sampling Strategies in Quicksort and Quickselect , 2002, SIAM J. Comput..

[27]  Salvador Roura,et al.  Improved master theorems for divide-and-conquer recurrences , 2001, JACM.

[28]  Alessandro Panconesi,et al.  Concentration of Measure for the Analysis of Randomized Algorithms , 2009 .

[29]  Naila Rahman Algorithms for Hardware Caches and TLB , 2002, Algorithms for Memory Hierarchies.

[30]  Robert Sedgewick Quicksort with Equal Keys , 1977, SIAM J. Comput..

[31]  Stefan Edelkamp,et al.  BlockQuicksort: Avoiding Branch Mispredictions in Quicksort , 2016, ESA.

[32]  Peter Sanders,et al.  How Branch Mispredictions Affect Quicksort , 2006, ESA.

[33]  Kok-Hooi Tan An asymptotic analysis of the number of comparisons in multipartition quicksort , 1993 .

[34]  P. Kam,et al.  : 4 , 1898, You Can Cross the Massacre on Foot.

[35]  Donald E. Knuth,et al.  The Art of Computer Programming: Volume 3: Sorting and Searching , 1998 .

[36]  Keith Bostic,et al.  Engineering Radix Sort , 1993, Comput. Syst..

[37]  Pascal Hennequin Analyse en moyenne d'algorithmes, tri rapide et arbres de recherche , 1991 .

[38]  W. Donald Frazer,et al.  Samplesort: A Sampling Approach to Minimal Storage Tree Sorting , 1970, JACM.