skip to main content
research-article

Optimal Partitioning for Dual-Pivot Quicksort

Published:17 November 2015Publication History
Skip Abstract Section

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

References

  1. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. 2009. Introduction to Algorithms (3rd ed.). MIT Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Devdatt P. Dubhashi and Alessandro Panconesi. 2009. Concentration of Measure for the Analysis of Randomized Algorithms. Cambridge University Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle Scholar
  4. C. A. R. Hoare. 1962. Quicksort. Computer Journal 5, 1 (1962), 10--15.Google ScholarGoogle ScholarCross RefCross Ref
  5. Donald E. Knuth. 1973. The Art of Computer Programming, Volume III: Sorting and Searching. Addison-Wesley.Google ScholarGoogle Scholar
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. Conrado Martínez and Salvador Roura. 2001. Optimal sampling strategies in quicksort and quickselect. SIAM Journal on Computing 31, 3 (2001), 683--705. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Salvador Roura. 2001. Improved master theorems for divide-and-conquer recurrences. Journal of the ACM 48, 2 (2001), 170--205. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Robert Sedgewick. 1975. Quicksort. Ph.D. Dissertation. Standford University.Google ScholarGoogle Scholar
  11. Robert Sedgewick. 1977. Quicksort with equal keys. SIAM J. Comput. 6, 2 (1977), 240--268.Google ScholarGoogle ScholarCross RefCross Ref
  12. Robert Sedgewick and Philippe Flajolet. 1996. An Introduction to the Analysis of Algorithms. Addison-Wesley-Longman. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. M. H. van Emden. 1970. Increasing the efficiency of quicksort. Communications of the ACM 13, 9 (1970), 563--567. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Sebastian Wild. 2013. Java 7’s Dual Pivot Quicksort. Master’s thesis. University of Kaiserslautern.Google ScholarGoogle Scholar
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. Sebastian Wild, Markus E. Nebel, and Conrado Martínez. 2014. Analysis of pivot sampling in dual-pivot quicksort. CoRR abs/1412.0193 (2014).Google ScholarGoogle Scholar
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Optimal Partitioning for Dual-Pivot Quicksort

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM Transactions on Algorithms
      ACM Transactions on Algorithms  Volume 12, Issue 2
      February 2016
      385 pages
      ISSN:1549-6325
      EISSN:1549-6333
      DOI:10.1145/2846106
      Issue’s Table of Contents

      Copyright © 2015 ACM

      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: 17 November 2015
      • Accepted: 1 March 2015
      • Revised: 1 February 2015
      • Received: 1 July 2014
      Published in talg Volume 12, Issue 2

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • research-article
      • Research
      • Refereed

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader