Mergeable heap
In computer science, a mergeable heap is an abstract data type, which is a heap supporting a merge operation.
Definition
A mergeable heap supports the usual heap operations:-
Make-Heap, create an empty heap. -
Insert, insert an elementxinto the heapH. -
Min, return the minimum element, orNilif no such element exists. -
Extract-Min, extract and return the minimum element, orNilif no such element exists.
-
Merge, combine the elements ofH1andH2into a single heap.Trivial implementation
Merge:-
x ← Extract-Min -
while x ≠ Nil - #
Insert - #
x ← Extract-Min
Extract-Min and Insert typically have to maintain the heap property.More efficient implementations
Examples of mergeable heap data structures include:A more complete list with performance comparisons can be found at.
In most mergeable heap structures, merging is the fundamental operation on which others are based. Insertion is implemented by merging a new single-element heap with the existing heap. Deletion is implemented by merging the children of the deleted node.