Prerequisites:Fibonacci Heap (Introduction)
Fibonacci Heap is a collection of trees with min-heap or max-heap property. In Fibonacci Heap, trees can can have any shape even all trees can be single nodes (This is unlike Binomial Heap where every tree has to be Binomial Tree).
In this article, we will discuss Insertion and Union operation on Fibonacci Heap.
Insertion: To insert a node in a Fibonacci heap H, the following algorithm is followed:
- Create a new node ‘x’.
- Check whether heap H is empty or not.
- If H is empty then:
- Make x as the only node in the root list.
- Set H(min) pointer to x.
- Insert x into root list and update H(min).
Union: Union of two Fibonacci heaps H1 and H2 can be accomplished as follows:
- Join root lists of Fibonacci heaps H1 and H2 and make a single Fibonacci heap H.
- If H1(min) < H2(min) then:
- H(min) = H1(min).
- H(min) = H2(min).
Following is a program to demonstrate building and inserting in a Fibonacci heap:
The root nodes of Heap are: 1-->2-->3-->4-->7-->5-->10 The heap has 7 nodes Min of heap is: 1
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Fibonacci Heap | Set 1 (Introduction)
- Fibonacci Heap - Deletion, Extract min and Decrease key
- Heap Sort for decreasing order using min heap
- Union-Find Algorithm | (Union By Rank and Find by Optimized Path Compression)
- Check if sum of Fibonacci elements in an Array is a Fibonacci number or not
- Convert min Heap to max Heap
- Check if a M-th fibonacci number divides N-th fibonacci number
- AVL Tree | Set 1 (Insertion)
- K-ary Heap
- Octree | Insertion and Searching
- Skip List | Set 2 (Insertion)
- Kth largest element after every insertion
- Insertion and Deletion in Heaps
- Insertion in a Trie recursively
- K’th Least Element in a Min-Heap
- Max Heap in Python
- Convert BST to Max Heap
- Max Heap in Java
- Skew Heap
- Min Heap in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.