A pairing heap is defined as a type of heap data structure with relatively easy implementation and superb practical amortized performance.
Pairing heaps are heap-ordered multiway tree structures, and can be denoted as simplified Fibonacci heaps.
They are considered a "robust choice" for implementing such Algorithms like Prim's MST Algorithm, and support the following operations (assuming a min-heap) −
- find-min − This function is responsible to return the top element of the heap.
- meld −This function is responsible to compare the two root elements, the smaller remains the root of the result, the larger element and its subtree is added as a child of this root.
- insert − This function is responsible to create a new heap for the inserted element and meld into the original heap.
- decrease-key (optional) − This function is responsible to remove the subtree rooted at the key to be decreased, replace the key with a smaller key, then meld the result back into the heap.
- delete-min − This function is responsible to remove the root and do repeated melds of its subtrees until one tree remains. Various merging strategies are employed.
- Each node has a pointer towards the left child and left child points towards the next sibling of the child.
- Example of Pairing Heap is given below −
The analysis of pairing heaps' time complexity was primarily inspired by that of splay trees. The amortized time per delete-min is considered as O(log n), and the operations find-min, meld, and insert run in O(1) amortized time.
Published on 02-Jan-2020 06:58:14