# Average-case results on heapsort

- Received:
- Revised:

DOI: 10.1007/BF01937350

- Cite this article as:
- Carlsson, S. BIT (1987) 27: 2. doi:10.1007/BF01937350

## Abstract

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 [log*n*]+0.299+*M*(*n*) comparisons, *) where*M*(*n*) is between 0 and 1. It is also shown that a heap can be constructed using 1.650*n*+*O*(log*n*) comparisons with this algorithm, the best result for any algorithm which does not use any extra space. The expected time to sort*n* elements is argued to be less than*n* log*n*+0.670*n*+*O*(log*n*), while simulation result points at an average case of*n* log n+0.4*n* 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([log*n*]−1.299+*L*(*n*)) where*L*(*n*) also is between 0 and 1, and the average cost for Floyd-Williams Heapsort is at least 2*n*log*n*−3.27*n*, 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.