BIT Numerical Mathematics

, Volume 27, Issue 1, pp 2–17 | Cite as

Average-case results on heapsort

  • Svante Carlsson
Part I Computer Science


A new algorithm for rearranging a heap is presented and analysed in the average case. The average case upper bound for deleting the maximum element of a random heap is improved, and is shown to be less than [logn]+0.299+M(n) comparisons, *) whereM(n) is between 0 and 1. It is also shown that a heap can be constructed using 1.650n+O(logn) comparisons with this algorithm, the best result for any algorithm which does not use any extra space. The expected time to sortn elements is argued to be less thann logn+0.670n+O(logn), while simulation result points at an average case ofn log n+0.4n which will make it the fastest in-place sorting algorithm. The same technique is used to show that the average number of comparisons when deleting the maximum element of a heap using Williams' algorithm for rearrangement is 2([logn]−1.299+L(n)) whereL(n) also is between 0 and 1, and the average cost for Floyd-Williams Heapsort is at least 2nlogn−3.27n, counting only comparisons. An analysis of the number of interchanges when deleting the maximum element of a random heap, which is the same for both algorithms, is also presented.

CR categories

E.2 F.2.2 


Sorting priority queues heaps average-case analysis heapsort 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    S. Carlsson,A variant of HEAPSORT with almost optimal number of comparisons, to appear in Information Processing Letters.Google Scholar
  2. 2.
    E. E. Doberkat,An average case analysis of Floyd's algorithm to construct heaps, Information and Control, 61: 114–131 (1984).CrossRefGoogle Scholar
  3. 3.
    E. E. Doberkat,Deleting the root of a heap, Acta Informatica, 17: 245–265 (1982).CrossRefGoogle Scholar
  4. 4.
    E. E. Doberkat,Inserting a new element into a heap, BIT 21 (1981), 255–269.Google Scholar
  5. 5.
    R. W. Floyd,Algorithm 245, Treesort; CACM, 7 (12): 701, (dec. 1964).Google Scholar
  6. 6.
    G. H. Gonnet,Handbook of Algorithms and Data Structures, Addison-Wesley, (1984).Google Scholar
  7. 7.
    G. H. Gonnet and J. I. Munro,Heaps on heaps, Proceedings ICALP, Aarhus 9: 282–291 (July 12–16 1982).Google Scholar
  8. 8.
    K. Mehlhorn,Data Structures and Algorithms 1: Sorting and Searching, Springer-Verlag (1984).Google Scholar
  9. 9.
    Th. Porter and I. Simon,Random insertion into a priority queue structure, IEEE Trans. Software Engineering, 1 SE-(1975) 292–298.Google Scholar
  10. 10.
    J. W. J. Williams,Algorithm 232, CACM, 7(6): 347–348, (June 1964).Google Scholar

Copyright information

© BIT Foundations 1987

Authors and Affiliations

  • Svante Carlsson
    • 1
  1. 1.Department of Computer SciencesLund UniversityLundSweden

Personalised recommendations