Mergeable heap
From Infogalactic: the planetary knowledge core
(Redirected from Meldable heap)
In computer science, a mergeable heap (also called a meldable heap) is an abstract data type, which is a heap supporting a merge operation.
Contents
Definition
A mergeable heap supports the following operations:[1]
Make-Heap()
, creating an empty heap.Insert(H,x)
, inserting an elementx
into the heapH
.Min(H)
, returning the minimum element, orNil
if no such element exists.Extract-Min(H)
, extracting and returning the minimum element, orNil
if no such element exists.Merge(H1,H2)
, combining the elements ofH1
andH2
.
Trivial implementation
It is straightforward to implement a mergeable heap given a simple heap:
Merge(H1,H2):
x ← Extract-Min(H2)
while x ≠ Nil
Insert(H1, x)
x ← Extract-Min(H2)
This can however be wasteful as each Extract-Min(H)
and Insert(H,x)
typically have to maintain the heap property.
More efficient implementations
Examples of mergeable heaps include:
A more complete list with performance comparisons can be found here.
See also
References
<templatestyles src="Reflist/styles.css" />
Cite error: Invalid <references>
tag; parameter "group" is allowed only.
<references />
, or <references group="..." />
- ↑ Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms. 2009, 3rd ed. The MIT Press. ISBN 978-0-262-53305-8.