Skip to main content
Log in

QuickHeapsort: Modifications and Improved Analysis

  • Published:
Theory of Computing Systems Aims and scope Submit manuscript

Abstract

QuickHeapsort is a combination of Quicksort and Heapsort. We show that the expected number of comparisons for QuickHeapsort is always better than for Quicksort if a usual median-of-constant strategy is used for choosing pivot elements. In order to obtain the result we present a new analysis for QuickHeapsort splitting it into the analysis of the partition-phases and the analysis of the heap-phases. This enables us to consider samples of non-constant size for the pivot selection and leads to better theoretical bounds for the algorithm. Furthermore, we introduce some modifications of QuickHeapsort. We show that for every input the expected number of comparisons is at most \(n\log _{2}n - 0.03n + o(n)\) for the in-place variant. If we allow n extra bits, then we can lower the bound to \( n\log _{2} n -0.997 n+ o (n)\). Thus, spending n extra bits we can save more that 0.96n comparisons if n is large enough. Both estimates improve the previously known results. Moreover, our non-in-place variant does essentially use the same number of comparisons as index based Heapsort variants and Relaxed-Weak-Heapsort which use \( n\log _{2}n -0.9 n+ o (n)\) comparisons in the worst case. However, index based Heapsort variants and Relaxed-Weak-Heapsort require \({\Theta }(n\log n)\) extra bits whereas we need n bits only. Our theoretical results are upper bounds and valid for every input. Our computer experiments show that the gap between our bounds and the actual values on random inputs is small. Moreover, the computer experiments establish QuickHeapsort as competitive with Quicksort in terms of running time.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1

Similar content being viewed by others

References

  1. Blum, M., Floyd, R.W., Pratt, V., Rivest, R.L., Tarjan, R.E.: Time bounds for selection. J. Comput. Syst. Sci. 7(4), 448–461 (1973)

    Article  MathSciNet  MATH  Google Scholar 

  2. Cantone, D., Cincotti, G.: QuickHeapsort, an efficient mix of classical sorting algorithms. Theor. Comput. Sci. 285(1), 25–42 (2002)

    Article  MathSciNet  MATH  Google Scholar 

  3. Carlsson, S., Chen, J., Mattsson, C.: Heaps with Bits. In: D.-Z. Du, X.-S. Zhang (eds.) ISAAC, vol. 834 of LNCS, pp. 288–296. Springer (1994)

  4. Chen, J.: A Framework for Constructing Heap-like structures in-place. In: K.-W. Ng, et al. (eds.) ISAAC, vol. 762 of LNCS, pp. 118–127. Springer (1993)

  5. Chen, J., Edelkamp, S., Elmasry, A., Katajainen, J.: In-place Heap Construction with Optimized Comparisons, Moves, and Cache Misses. In: B. Rovan, V. Sassone, P. Widmayer (eds.) MFCS, vol. 7464 of LNCS, pp. 259–270. Springer (2012)

  6. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms. The MIT Press, 3rd edn. (2009)

  7. Dutton, R.D.: Weak-heap sort. BIT 33(3), 372–381 (1993)

    Article  MathSciNet  Google Scholar 

  8. Edelkamp, S., Stiegeler, P.: Implementing HEAPSORT with \(n \lg n - 0.9n\) and QUICKSORT with \(n \lg n + 0.2n\) comparisons. ACM J. of Exp. Alg., 7:5 (2002)

  9. Floyd, R.W.: Algorithm 245: Treesort. Commun. ACM 7(12), 701 (1964)

    Article  Google Scholar 

  10. Gonnet, G.H., Munro, J.I.: Heaps on Heaps. SIAM J. Comput. 15(4), 964–971 (1986)

    Article  MathSciNet  MATH  Google Scholar 

  11. Katajainen, J.: The ultimate heapsort. In: X. Lin (ed.) CATS, vol. 20 of Australian Computer Science Communications, pp. 87–96. Springer-Verlag (1998)

  12. Knuth, D.E.: The art of computer programming. vol. 3 Addison-Wesley (1998)

  13. Martínez, C., Roura, S.: Optimal sampling strategies in Quicksort and Quickselect. SIAM J. Comput. 31(3), 683–705 (2001)

    Article  MathSciNet  MATH  Google Scholar 

  14. McDiarmid, C., Reed, B.A.: Building Heaps Fast. J. Alg. 10(3), 352–365 (1989)

    Article  MathSciNet  MATH  Google Scholar 

  15. Reinhardt, K.: Sorting in-place with a worst case complexity of \( n \log n -1.3 n + O(\log n)\) comparisons and \(\epsilon n \log n + O(1)\) transports. In: T. Ibaraki, et al. (eds.) ISAAC, vol. 650 of LNCS, pp. 489–498. Springer (1992)

  16. Wang, X.-D., Wu, Y.-J.: An improved HEAPSORT Algorithm with \(n\lg n - 0.788928n\) comparisons in the Worst Case. J. Comput. Sci. Techn. 22, 898–903 (2007)

    Article  Google Scholar 

  17. Wegener, I.: The worst case complexity of McDiarmid and Reed’s variant of Bottom-Up-Heap sort is less than \(n \lg n + 1.1n\). In: C. Choffrut, M. Jantzen (eds.) STACS, vol. 480 of LNCS, pp. 137–147. Springer (1991)

  18. Wegener, I.: BOTTOM-UP-HEAPSORT, a new variant of HEAPSORT, beating, on an average, QUICKSORT (if n is not very small). Theor. Comp. Sci. 118(1), 81–98 (1993)

    Article  MathSciNet  MATH  Google Scholar 

Download references

Acknowledgments

We thank Martin Dietzfelbinger, Stefan Edelkamp, Jyrki Katajainen and the anonymous referees for various comments which improved the presentation of the paper. We also thank Simon Paridon for helping us with the implementation of the algorithms.

Conflict of interests

The authors declare that they have no conflict of interest.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Armin Weiß.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Diekert, V., Weiß, A. QuickHeapsort: Modifications and Improved Analysis. Theory Comput Syst 59, 209–230 (2016). https://doi.org/10.1007/s00224-015-9656-y

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s00224-015-9656-y

Keywords

Navigation