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.
Similar content being viewed by others
References
Knuth D E. The Art of Computer Programming — Sorting and Searching. 2nd Edition, New York: Addison Wesley, 1998.
Floyd R W. Algorithm 245: Treesort 3. Communications of the ACM, 1964, 7(4): 701.
Williams J W J. Algorithm 232: HEAPSORT. Communications of the ACM, 1964, 7(4): 347–348.
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.
Carlsson S. A variant of HEAPSORT with almost optimal number of comparisons. Information Processing Letters, 1987, 24(3): 247–250.
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.
Gonnet G H, Munro J I. Heaps on heaps. SIAM Journal on Computing, 1986, 15(6): 964–971.
McDiarmid C J H, Reed B A. Building heaps fast. Journal of Algorithms, 1989, 10(3): 352–365.
Hoare C A R. Quicksort. Computer Journal, 5(1): 10–15.
Dutton R D. Weak heap sort. BIT, 1993, 33(3): 372–381.
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.
Cantone D, Cincotti G. QuickHeapsort, an efficient mix of classical sorting algorithms. Theoretical Computer Science, 2002, 285(1): 25–42.
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.
Ding Y, Weiss M A. Best case lower bounds for Heapsort. Computing, 1992, 49(1): 1–9.
Z Li, Bruce A Reed. Heap building bounds. LNCS, 2005, 3608(1): 14–23.
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.
Author information
Authors and Affiliations
Corresponding author
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.
Rights 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
Received:
Revised:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s11390-007-9106-7