Skip to main content
Log in

An Improved HEAPSORT Algorithm with nlogn − 0.788928n Comparisons in the Worst Case

  • Short Paper
  • Published:
Journal of Computer Science and Technology Aims and scope Submit manuscript

Abstract

A new variant of HEAPSORT is presented in this paper. The algorithm is not an internal sorting algorithm in the strong sense, since extra storage for n integers is necessary. The basic idea of the new algorithm is similar to the classical sorting algorithm HEAPSORT, but the algorithm rebuilds the heap in another way. The basic idea of the new algorithm is it uses only one comparison at each node. The new algorithm shift walks down a path in the heap until a leaf is reached. The request of placing the element in the root immediately to its destination is relaxed. The new algorithm requires about n log n − 0.788928n comparisons in the worst case and n log n − n comparisons on the average which is only about 0.4n more than necessary. It beats on average even the clever variants of QUICKSORT, if n is not very small. The difference between the worst case and the best case indicates that there is still room for improvement of the new algorithm by constructing heap more carefully.

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.

Institutional subscriptions

Similar content being viewed by others

References

  1. Knuth D E. The Art of Computer Programming — Sorting and Searching. 2nd Edition, New York: Addison Wesley, 1998.

    Google Scholar 

  2. Floyd R W. Algorithm 245: Treesort 3. Communications of the ACM, 1964, 7(4): 701.

    Article  MathSciNet  Google Scholar 

  3. Williams J W J. Algorithm 232: HEAPSORT. Communications of the ACM, 1964, 7(4): 347–348.

    Google Scholar 

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

    Article  MATH  MathSciNet  Google Scholar 

  5. Carlsson S. A variant of HEAPSORT with almost optimal number of comparisons. Information Processing Letters, 1987, 24(3): 247–250.

    Article  MATH  MathSciNet  Google Scholar 

  6. Wegener I. The worst case complexity of McDiarmid and Reed's variant of BOTTOM-UP HEAPSORT is less than n log n + 1.1n. Information and Computation, 1992, 97(1): 86–96.

    Article  MATH  MathSciNet  Google Scholar 

  7. Gonnet G H, Munro J I. Heaps on heaps. SIAM Journal on Computing, 1986, 15(6): 964–971.

    Article  MATH  MathSciNet  Google Scholar 

  8. McDiarmid C J H, Reed B A. Building heaps fast. Journal of Algorithms, 1989, 10(3): 352–365.

    Article  MATH  MathSciNet  Google Scholar 

  9. Hoare C A R. Quicksort. Computer Journal, 5(1): 10–15.

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

    Article  MathSciNet  Google Scholar 

  11. Edelkamp S, Stiegeler P. Implementing HEAPSORT with n log n − 0.9n and QUICKSORT with n log n + 0.2n comparisons. ACM Journal of Experimental Algorithmics (JEA), 2002, 7(1): 1–20.

    MathSciNet  Google Scholar 

  12. Cantone D, Cincotti G. QuickHeapsort, an efficient mix of classical sorting algorithms. Theoretical Computer Science, 2002, 285(1): 25–42.

    Article  MATH  MathSciNet  Google Scholar 

  13. Carlsson S, Chen J. The complexity of heaps. In Proc. the Third Annual ACM-SIAM Symposium on Discrete Algorithms, SIAM, Philadelphia, PA, October 1992, pp.393–402.

  14. Ding Y, Weiss M A. Best case lower bounds for Heapsort. Computing, 1992, 49(1): 1–9.

    Article  MATH  MathSciNet  Google Scholar 

  15. Z Li, Bruce A Reed. Heap building bounds. LNCS, 2005, 3608(1): 14–23.

    MathSciNet  Google Scholar 

  16. Reinhardt K. Sorting in place with a worst case complexity of n log n − 1.3n + O(log n) comparisons and ɛnlog n + O(1) transports. LNCS, 1992, 650(6): 489–499.

    MathSciNet  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Xiao-Dong Wang.

Additional information

Supported by the Natural Science Foundation of Fujian under Grant No. A0510008.

Electronic Supplementary Material

Below is the link to the electronic supplementary material.

(PDF 79 kb)

Rights and permissions

Reprints and permissions

About this article

Cite this article

Wang, XD., Wu, YJ. An Improved HEAPSORT Algorithm with nlogn − 0.788928n Comparisons in the Worst Case. J. Comput. Sci. Technol. 22, 898–903 (2007). https://doi.org/10.1007/s11390-007-9106-7

Download citation

  • Received:

  • Revised:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s11390-007-9106-7

Keywords

Navigation