, Volume 75, Issue 4, pp 632–683 | Cite as

Analysis of Pivot Sampling in Dual-Pivot Quicksort: A Holistic Analysis of Yaroslavskiy’s Partitioning Scheme

  • Markus E. Nebel
  • Sebastian WildEmail author
  • Conrado Martínez


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 paper, we extend the analysis to the case where the two pivots are chosen as fixed order statistics of a random sample. Surprisingly, dual-pivot Quicksort then needs more comparisons than a corresponding version of classic Quicksort, so it is clear that counting comparisons is not sufficient to explain the running time advantages observed for Yaroslavskiy’s algorithm in practice. Consequently, we take a more holistic approach and give also the precise leading term of the average number of swaps, the number of executed Java Bytecode instructions and the number of scanned elements, a new simple cost measure that approximates I/O costs in the memory hierarchy. We determine optimal order statistics for each of the cost measures. It turns out that the asymmetries in Yaroslavskiy’s algorithm render pivots with a systematic skew more efficient than the symmetric choice. Moreover, we finally have a convincing explanation for the success of Yaroslavskiy’s algorithm in practice: compared with corresponding versions of classic single-pivot Quicksort, dual-pivot Quicksort needs significantly less I/Os, both with and without pivot sampling.


Quicksort Dual-pivot Yaroslavskiy’s partitioning method  Median of three Average-case analysis I/O operations External-memory model 



We thank two anonymous reviewers for their careful reading and helpful comments.


  1. 1.
    Aumüller, M., Dietzfelbinger, M.: Optimal partitioning for dual pivot quicksort. In: Fomin, F.V., Freivalds, R., Kwiatkowska, M., Peleg, D. (ed.) International Colloquium on Automata, Languages and Programming, pp. 33–44. Springer, LNCS, vol 7965 (2013)Google Scholar
  2. 2.
    Bentley, J.L., McIlroy, M.D.: Engineering a sort function. Softw. Pract. Exp. 23(11), 1249–1265 (1993)CrossRefGoogle Scholar
  3. 3.
    Chern, H.H., Hwang, H.K., Tsai, T.H.: An asymptotic theory for cauchy-euler differential equations with applications to the analysis of algorithms. J. Algorithms 44(1), 177–225 (2002)MathSciNetCrossRefzbMATHGoogle Scholar
  4. 4.
    Chung, K.L.: A Course in Probability Theory, 3rd edn. Academic Press, Waltham (2001)Google Scholar
  5. 5.
    Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 3rd edn. MIT Press, Cambridge (2009)zbMATHGoogle Scholar
  6. 6.
    David, H.A., Nagaraja, H.N.: Order Statistics, 3rd edn. Wiley-Interscience, New York (2003)CrossRefzbMATHGoogle Scholar
  7. 7.
    Durand, M.: Asymptotic analysis of an optimized quicksort algorithm. Inform. Process. Lett. 85(2), 73–77 (2003)MathSciNetCrossRefzbMATHGoogle Scholar
  8. 8.
    Estivill-Castro, V., Wood, D.: A survey of adaptive sorting algorithms. ACM Comput. Surv. 24(4), 441–476 (1992)CrossRefGoogle Scholar
  9. 9.
    Fill, J., Janson, S.: The number of bit comparisons used by quicksort: an average-case analysis. Elect. J. Prob. 17, 1–22 (2012)MathSciNetzbMATHGoogle Scholar
  10. 10.
    Graham, R.L., Knuth, D.E., Patashnik, O.: Concrete Mathematics: A Foundation for Computer Science. Addison-Wesley, Boston (1994)zbMATHGoogle Scholar
  11. 11.
    Hennequin, P.: Analyse en moyenne d’algorithmes : tri rapide et arbres de recherche. PhD Thesis, Ecole Politechnique, Palaiseau (1991)Google Scholar
  12. 12.
    Hennessy, J.L., Patterson, D.A.: Computer Architecture: A Quantitative Approach, 4th edn. Morgan Kaufmann Publishers, Burlington (2006)zbMATHGoogle Scholar
  13. 13.
    Hoare, C.A.R.: Algorithm 65: Find. Commun. ACM 4(7), 321–322 (1961)CrossRefGoogle Scholar
  14. 14.
    Kaligosi, K., Sanders, P.: How branch mispredictions affect quicksort. In: Erlebach, T., Azar, Y. (ed.) European Symposium on Algorithms, pp. 780–791. Springer, LNCS, vol 4168, (2006)Google Scholar
  15. 15.
    Kushagra, S., López-Ortiz, A., Qiao, A., Munro, J.I.: Multi-pivot quicksort: Theory and experiments. In: McGeoch, C.C., Meyer, U. (ed.) Meeting on Algorithm Engineering and Experiments, pp. 47–60. SIAM (2014)Google Scholar
  16. 16.
    LaMarca, A., Ladner, R.E.: The influence of caches on the performance of sorting. J. Algorithms 31(1), 66–104 (1999)MathSciNetCrossRefzbMATHGoogle Scholar
  17. 17.
    Mahmoud, H.M.: Sorting: A Distribution Theory. Wiley, New York (2000)CrossRefzbMATHGoogle Scholar
  18. 18.
    Martínez, C., Roura, S.: Optimal sampling strategies in quicksort and quickselect. SIAM J. Comput. 31(3), 683–705 (2001)MathSciNetCrossRefzbMATHGoogle Scholar
  19. 19.
    Martínez, C., Nebel, M.E., Wild, S.: Analysis of branch misses in quicksort. In: Sedgewick, R., Ward, M.D. (eds.) Meeting on Analytic Algorithmics and Combinatorics, pp. 114–128. SIAM, Philadelphia (2014)Google Scholar
  20. 20.
    Musser, D.R.: Introspective sorting and selection algorithms. Softw. Pract. Exp. 27(8), 983–993 (1997)CrossRefGoogle Scholar
  21. 21.
    Nebel, M.E., Wild, S.: Pivot sampling in dual-pivot quicksort. In: Bousquet-Mélou, M., Soria, M. (ed.) International Conference on Probabilistic, Combinatorial and Asymptotic Methods for the Analysis of Algorithms, DMTCS-HAL Proceedings Series, vol BA, pp. 325–338 (2014)Google Scholar
  22. 22.
    Neininger, R.: On a multivariate contraction method for random recursive structures with applications to quicksort. Random Struct. Algorithms 19(3–4), 498–524 (2001)MathSciNetCrossRefzbMATHGoogle Scholar
  23. 23.
    Roura, S.: Improved master theorems for divide-and-conquer recurrences. J. ACM 48(2), 170–205 (2001)MathSciNetCrossRefzbMATHGoogle Scholar
  24. 24.
    Sedgewick, R.: Quicksort. PhD Thesis, Stanford University (1975)Google Scholar
  25. 25.
    Sedgewick, R.: The analysis of quicksort programs. Acta Inform. 7(4), 327–355 (1977)MathSciNetCrossRefzbMATHGoogle Scholar
  26. 26.
    Sedgewick, R.: Implementing quicksort programs. Commun. ACM 21(10), 847–857 (1978)CrossRefzbMATHGoogle Scholar
  27. 27.
    Vallée, B., Clément, J., Fill, J.A., Flajolet, P.: The number of symbol comparisons in quicksort and quickselect. In: Albers, S., Marchetti-Spaccamela, A., Matias, Y., Nikoletseas, S., Thomas, W. (ed.) International Colloquium on Automata, Languages and Programming, pp 750–763. Springer, LNCS, vol 5555, (2009)Google Scholar
  28. 28.
    van Emden, M.H.: Increasing the efficiency of quicksort. Commun. ACM 13(9), 563–567 (1970)CrossRefzbMATHGoogle Scholar
  29. 29.
    Wild, S.: Java 7’s Dual-Pivot Quicksort. Master thesis, University of Kaiserslautern (2012)Google Scholar
  30. 30.
    Wild, S., Nebel, M.E.: Average case analysis of Java 7’s dual pivot quicksort. In: Epstein, L., Ferragina, P. (ed.) European Symposium on Algorithms, pp. 825–836. Springer, LNCS, vol 7501, (2012)Google Scholar
  31. 31.
    Wild, S., Nebel, M.E., Reitzig, R., Laube, U.: Engineering Java 7’s dual pivot quicksort using MaLiJAn. In: Sanders, P., Zeh, N. (eds.) Meeting on Algorithm Engineering and Experiments, pp. 55–69. SIAM, Philadelphia (2013)Google Scholar
  32. 32.
    Wild, S., Nebel, M.E., Mahmoud, H.: Analysis of quickselect under Yaroslavskiy’s dual-pivoting algorithm. Algorithmica (to appear) (2014). doi: 10.1007/s00453-014-9953-x
  33. 33.
    Wild, S., Nebel, M.E., Neininger, R.: Average case and distributional analysis of Java 7’s dual pivot quicksort. ACM Trans. Algorithms 11(3), 22:1–22:42 (2015)MathSciNetCrossRefGoogle Scholar

Copyright information

© Springer Science+Business Media New York 2015

Authors and Affiliations

  • Markus E. Nebel
    • 1
    • 2
  • Sebastian Wild
    • 1
    Email author
  • Conrado Martínez
    • 3
  1. 1.Computer Science DepartmentUniversity of KaiserslauternKaiserslauternGermany
  2. 2.Department of Mathematics and Computer ScienceUniversity of Southern DenmarkOdenseDenmark
  3. 3.Department of Computer ScienceUniv. Politècnica de CatalunyaBarcelonaSpain

Personalised recommendations