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).
Article PDF
Similar content being viewed by others
Avoid common mistakes on your manuscript.
References
Aho, A.V., Hopcroft, J.E., Ullman, J.D.: The design and analysis of computer algorithms, p. 99. Reading, MA: Addison-Wesley 1974
Aho, A.V., Hopcroft, J.E., Ullman, J.D.: Data structures and algorithms. Reading, MA: Addison-Wesley 1983
Brown, M.R.: The analysis of a practical and nearly optimal priority queue. New York: Garland Publishing 1980
Floyd, R.W.: Algorithm 245, Treesort 3. CACM 7, 701 (1964)
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)
Gonnet, G.H.: A handbook of algorithms and data structures. Reading, MA: Addison-Wesley 1984
Gonnet, G.H., Munro, I.J.: Heaps on Heaps. Proc. ICALP, Aarhus 9, pp.282–291 (July 1982)
Knuth, D.E.: The art of computer programming. Vol. 3: Sorting and searching. Reading, MA: Addison-Wesley 1973
Tarjan, R.E.: Data Structures and Network Algorithms. Philadelphia, PA: Soc. Ind. Appl. Math. 1983
Vuillemin, J.: A data structure for manipulating priority queues. CACM 21, 309–315 (1978)
Williams, J.W.J.: Algorithm 232, heapsort. CACM 7, 347–348 (1964)
Author information
Authors and Affiliations
Additional information
This work was done while the authors were at McGill University, Montréal, Canada
Rights 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
Received:
Published:
Issue Date:
DOI: https://doi.org/10.1007/BF00264229