Skip to main content
Log in

An algorithm for merging heaps

  • Published:
Acta Informatica Aims and scope Submit manuscript

Summary

We present an algorithm to merge priority queues organized as heaps. The worst case number of comparisons required to merge two heaps of sizes k and n is O(log(n)*log(k)). The algorithm requires O(k) +log(n)*log (k)) data movements if heaps are implemented using arrays and O(log(n)*log(k)) for a pointer-based implementation. Previous algorithms require either O(n+k) data movements and comparisons, or O(k*log(log(n+k))) comparisons and O(k*log(n+k)) data movements. The algorithm presented in this paper improves on the previous algorithms for the case when k>log(n).

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. Aho, A.V., Hopcroft, J.E., Ullman, J.D.: The design and analysis of computer algorithms, p. 99. Reading, MA: Addison-Wesley 1974

    MATH  Google Scholar 

  2. Aho, A.V., Hopcroft, J.E., Ullman, J.D.: Data structures and algorithms. Reading, MA: Addison-Wesley 1983

    MATH  Google Scholar 

  3. Brown, M.R.: The analysis of a practical and nearly optimal priority queue. New York: Garland Publishing 1980

    Google Scholar 

  4. Floyd, R.W.: Algorithm 245, Treesort 3. CACM 7, 701 (1964)

    Article  Google Scholar 

  5. Francon, J., Viennot, G., Vuillemin, J.: Description and analysis of an efficient priority queue representation. Proc. 19th Ann. Symp. Found. Comput Sci. MI: Ann Arbor, pp. 1–7 (1978)

  6. Gonnet, G.H.: A handbook of algorithms and data structures. Reading, MA: Addison-Wesley 1984

    MATH  Google Scholar 

  7. Gonnet, G.H., Munro, I.J.: Heaps on Heaps. Proc. ICALP, Aarhus 9, pp.282–291 (July 1982)

  8. Knuth, D.E.: The art of computer programming. Vol. 3: Sorting and searching. Reading, MA: Addison-Wesley 1973

    MATH  Google Scholar 

  9. Tarjan, R.E.: Data Structures and Network Algorithms. Philadelphia, PA: Soc. Ind. Appl. Math. 1983

    Book  MATH  Google Scholar 

  10. Vuillemin, J.: A data structure for manipulating priority queues. CACM 21, 309–315 (1978)

    Article  MathSciNet  MATH  Google Scholar 

  11. Williams, J.W.J.: Algorithm 232, heapsort. CACM 7, 347–348 (1964)

    Article  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Additional information

This work was done while the authors were at McGill University, Montréal, Canada

Rights and permissions

Reprints and permissions

About this article

Cite this article

Sack, J.R., Strothotte, T. An algorithm for merging heaps. Acta Informatica 22, 171–186 (1985). https://doi.org/10.1007/BF00264229

Download citation

  • Received:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/BF00264229

Keywords

Navigation