Pairing Heap is like a simplified form Fibonacci Heap. It also maintains the property of min heap which is parent value is less than its child nodes value. It can be considered as a self-adjusting binomial heap.
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:
Join or Merge in Pairing Heap
To join the two heap, first, we compare the root node of the heap if the root node of the first heap is smaller than the root node of the second heap then root node of the second heap becomes a left child of the root node of the first heap otherwise vice-versa. The time complexity of this process is O(1).
Example of Merge is given Below:
Insertion in Pairing Heap:
To insert a new node in heap, create a new node and Merge it with existing heap as explained above. Therefore, the time complexity of this function is O(1).
Example of Insertion is given below:
Deletion in Pairing Heap:
Deletion in Pairing Heap only happens at the root node. First delete links between root, left child and all the siblings of the left child. Then Merge tree subtrees that are obtained by detaching the left child and all siblings by the two pass method and delete the root node. Merge the detached subtrees from left to right in one pass and then merge the subtrees from right to left to form the new heap without violation of conditions of min-heap. This process takes O(log n) time where n is the number of nodes.
Example of Deletion is given below:
Below is the implementation of the above approach:
1 2 False
- Heap Sort for decreasing order using min heap
- Convert min Heap to max Heap
- K-ary Heap
- Convert BST to Max Heap
- Skew Heap
- K’th Least Element in a Min-Heap
- Max Heap in Java
- Convert BST to Min Heap
- Binomial Heap
- Binary Heap
- Where is Heap Sort used practically?
- Minimum element in a max heap
- K-th Greatest Element in a Max-Heap
- Implementation of Binomial Heap
- Maximum element in min heap
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.