Abstract

We investigate the complexity of constructing heaps. The heap construction problem has been extensively studied. However, there was no algorithm for building heaps that is optimal in both the worst and average cases simultaneously. In particular, the worst-case fastest algorithm, proposed by Gonnet and Munro, takes 1.625n comparisons to build an n-element heap (with an average cost of 1.5803n comparisons). The best known average-case upper bound of 1.5212n comparisons was derived by McDiarmid and Reed, which has a worst-case performance of 2n comparisons. Both algorithms require extra space and were conjectured to be optimal respectively in the worst and the average case. In this paper, we design a heap construction algorithm that takes at most 1.625n and 1.500n comparisons in the worst and average cases, respectively. Our algorithm not only improves over the previous best known average-case result by McDiarmid and Reed, but also achieves the best known worst-case upper bound due to Gonnet and Munro. Moreover, we also show that a heap on n elements can be constructed in-situ using at most 1.528n comparisons on average and 2n comparisons in the worst case. This is only 0.007n comparisons more than that of McDiarmid and Reed's algorithm, while the latter needs n bits of extra space.

Full Text
Paper version not known

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call