In previous article, we have discussed about the concepts related to Binomial heap.
Examples Binomial Heap:
12------------10--------------------20 / \ / | \ 15 50 70 50 40 | / | | 30 80 85 65 | 100 A Binomial Heap with 13 nodes. It is a collection of 3 Binomial Trees of orders 0, 2 and 3 from left to right. 10--------------------20 / \ / | \ 15 50 70 50 40 | / | | 30 80 85 65 | 100
In this article, implementation of Binomial Heap is discussed. Following functions implemented :
- insert(H, k): Inserts a key ‘k’ to Binomial Heap ‘H’. This operation first creates a Binomial Heap with single key ‘k’, then calls union on H and the new Binomial heap.
- getMin(H): A simple way to getMin() is to traverse the list of root of Binomial Trees and return the minimum key. This implementation requires O(Logn) time. It can be optimized to O(1) by maintaining a pointer to minimum key root.
- extractMin(H): This operation also uses union(). We first call getMin() to find the minimum key Binomial Tree, then we remove the node and create a new Binomial Heap by connecting all subtrees of the removed minimum node. Finally we call union() on H and the newly created Binomial Heap. This operation requires O(Logn) time.
The heap is: 50 10 30 40 20 After deleing 10, the heap is: 20 30 40 50
This article is contributed by Sahil Chhabra (akku) and Arun Mittal. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between Binary Heap, Binomial Heap and Fibonacci Heap
- Implementation of Binomial Heap | Set - 2 (delete() and decreseKey())
- Memory representation of Binomial Heap
- Binomial Heap
- Convert min Heap to max Heap
- Heap Sort for decreasing order using min heap
- Difference between Min Heap and Max Heap
- Applications of Heap Data Structure
- Tournament Tree (Winner Tree) and Binary Heap
- Time Complexity of building a heap
- Why is Binary Heap Preferred over BST for Priority Queue?
- Fibonacci Heap | Set 1 (Introduction)
- Check if a given Binary Tree is Heap
- K-ary Heap
- Heap in C++ STL | make_heap(), push_heap(), pop_heap(), sort_heap(), is_heap, is_heap_until()
- Where is Heap Sort used practically?
- Binary Heap
- Array Representation Of Binary Heap
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- How to implement stack using priority queue or heap?