Open In App

Fibonacci Heap | Set 1 (Introduction)

Last Updated : 19 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

INTRODUCTION:

  1. A Fibonacci heap is a data structure used for implementing priority queues. It is a type of heap data structure, but with several improvements over the traditional binary heap and binomial heap data structures.
  2. The key advantage of a Fibonacci heap over other heap data structures is its fast amortized running time for operations such as insert, merge and extract-min, making it one of the most efficient data structures for these operations. The running time of these operations in a Fibonacci heap is O(1) for insert, O(log n) for extract-min and O(1) amortized for merge.
  3. A Fibonacci heap is a collection of trees, where each tree is a heap-ordered multi-tree, meaning that each tree has a single root node with its children arranged in a heap-ordered manner. The trees in a Fibonacci heap are organized in such a way that the root node with the smallest key is always at the front of the list of trees.
  4. In a Fibonacci heap, when a new element is inserted, it is added as a singleton tree. When two heaps are merged, the root list of one heap is simply appended to the root list of the other heap. When the extract-min operation is performed, the tree with the minimum root node is removed from the root list and its children are added to the root list.
  5. One unique feature of a Fibonacci heap is the use of lazy consolidation, which is a technique for improving the efficiency of the merge operation. In lazy consolidation, the merging of trees is postponed until it is necessary, rather than performed immediately. This allows for the merging of trees to be performed more efficiently in batches, rather than one at a time.

In summary, a Fibonacci heap is a highly efficient data structure for implementing priority queues, with fast amortized running times for operations such as insert, merge and extract-min. Its use of lazy consolidation and its multi-tree structure make it a superior alternative to traditional binary and binomial heaps in many applications.

Heaps are mainly used for implementing priority queue. We have discussed the below heaps in previous posts. 

In terms of Time Complexity, Fibonacci Heap beats both Binary and Binomial Heap. 

Below are amortized time complexities of the Fibonacci Heap

1) Find Min:      ?(1)     [Same as  Binary but not Binomial since binomial has o(log n)]
2) Delete Min:    O(Log n) [?(Log n) in both Binary and Binomial]
3) Insert:        ?(1)     [?(Log n) in Binary and ?(1) in Binomial]
4) Decrease-Key:  ?(1)     [?(Log n) in both Binary and Binomial]
5) Merge:         ?(1)     [?(m Log n) or ?(m+n) in Binary and
                            ?(Log n) in Binomial]

Like Binomial Heap, Fibonacci Heap is a collection of trees with min-heap or max-heap properties. In Fibonacci Heap, trees can have any shape even if all trees can be single nodes (This is unlike Binomial Heap where every tree has to be a Binomial Tree). 

Below is an example Fibonacci Heap taken from here

FibonacciHeap

Fibonacci Heap maintains a pointer to the minimum value (which is the root of a tree). All tree roots are connected using a circular doubly linked list, so all of them can be accessed using a single ‘min’ pointer. 

The main idea is to execute operations in a “lazy” way. For example merge operation simply links two heaps, insert operation simply adds a new tree with a single node. The operation extract minimum is the most complicated operation. It does delay the work of consolidating trees. This makes delete also complicated as delete first decreases the key to minus infinite, then calls extract minimum. 

Below are some interesting facts about Fibonacci Heap 

  1. The reduced time complexity of Decrease-Key has importance in Dijkstra and Prim algorithms. With Binary Heap, the time complexity of these algorithms is O(VLogV + ELogV). If Fibonacci Heap is used, then time complexity is improved to O(VLogV + E)
  2. Although Fibonacci Heap looks promising time complexity-wise, it has been found slow in practice as hidden constants are high (Source Wiki).
  3. Fibonacci heaps is mainly called so because Fibonacci numbers are used in the running time analysis. Also, every node in Fibonacci Heap has a degree at most O(log n) and the size of a subtree rooted in a node of degree k is at least Fk+2, where Fk is the kth Fibonacci number.

Advantages of Fibonacci Heap:

  1. Fast amortized running time: The running time of operations such as insert, extract-min and merge in a Fibonacci heap is O(1) for insert, O(log n) for extract-min and O(1) amortized for merge, making it one of the most efficient data structures for these operations.
  2. Lazy consolidation: The use of lazy consolidation allows for the merging of trees to be performed more efficiently in batches, rather than one at a time, improving the efficiency of the merge operation.
  3. Efficient memory usage: Fibonacci heaps have a relatively small constant factor compared to other data structures, making them a more memory-efficient choice in some applications.

Disadvantages of Fibonacci Heap:

  1. Increased complexity: The structure and operations of a Fibonacci heap are more complex than those of a binary or binomial heap, making it a less intuitive data structure for some users.
  2. Less well-known: Compared to other data structures, Fibonacci heaps are less well-known and widely used, making it more difficult to find resources and support for implementation and optimization.

References and books:

  1. “Introduction to Algorithms” by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein.
  2. “Data Structures and Algorithms in Java” by Michael T. Goodrich, Roberto Tamassia and Michael H. Goldwasser.
  3. “Fibonacci Heaps and Their Uses in Improved Network Optimization Algorithms” by Michael L. Fredman and Robert E. Tarjan.
  4. “Fibonacci Heaps and Their Uses in Improved Network Optimization Algorithms” by J. Ian Munro and Robert E. Tarjan.

We will soon be discussing Fibonacci Heap operations in detail. 


Previous Article
Next Article

Similar Reads

Difference between Binary Heap, Binomial Heap and Fibonacci Heap
Binary Heap:A Binary Heap is a Binary Tree with following properties. It’s a complete binary tree i.e., all levels are completely filled except possibly the last level and the last level has all keys as left as possible. This property of Binary Heap makes them suitable to be stored in an array. A Binary Heap is either Min Heap or Max Heap. In a Min
2 min read
Convert Min Heap to Max Heap
Given an array representation of min Heap, convert it to max Heap. Examples: Input: arr[] = {3, 5, 9, 6, 8, 20, 10, 12, 18, 9} 3 / \ 5 9 / \ / \ 6 8 20 10 / \ /12 18 9 Output: arr[] = {20, 18, 10, 12, 9, 9, 3, 5, 6, 8} 20 / \ 18 10 / \ / \ 12 9 9 3 / \ /5 6 8 Input: arr[] = {3, 4, 8, 11, 13}Output: arr[] = {13, 11, 8, 4, 3} Approach: To solve the p
10 min read
Heap Sort for decreasing order using min heap
Given an array of elements, sort the array in decreasing order using min heap. Examples: Input : arr[] = {5, 3, 10, 1} Output : arr[] = {10, 5, 3, 1} Input : arr[] = {1, 50, 100, 25} Output : arr[] = {100, 50, 25, 1} Prerequisite: Heap sort using min heap. Algorithm : Build a min heap from the input data. At this point, the smallest item is stored
13 min read
When building a Heap, is the structure of Heap unique?
What is Heap? A heap is a tree based data structure where the tree is a complete binary tree that maintains the property that either the children of a node are less than itself (max heap) or the children are greater than the node (min heap). Properties of Heap: Structural Property: This property states that it should be A Complete Binary Tree. For
4 min read
Difference between Min Heap and Max Heap
A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Since a heap is a complete binary tree, a heap with N nodes has log N height. It is useful to remove the highest or lowest priority element. It is typically represented as an array. There are two types of Heaps in the data structure. Min-HeapIn a Min-Heap the
3 min read
What's the relationship between "a" heap and "the" heap?
A Heap: "A Heap" refers to the heap data structure where we can store data in a specific order. Heap is a Tree-based data structure where the tree is a complete binary tree. Heap is basically of two types: Max-Heap: The key at the Root node of the tree will be the greatest among all the keys present in that heap and the same property will be follow
15+ min read
Fibonacci Heap - Insertion and Union
Fibonacci Heap is a collection of trees with min-heap or max-heap property. In Fibonacci Heap, trees can have any shape even all trees can be single nodes (This is unlike Binomial Heap where every tree has to be a Binomial Tree). In this article, we will discuss Insertion and Union operation on Fibonacci Heap. Prerequisites: Fibonacci Heap (Introdu
7 min read
Fibonacci Heap - Deletion, Extract min and Decrease key
In the last post, we discussed the Insertion and Union of Fibonacci Heaps. In this post, we will discuss Extract_min(), Decrease_key() and Deletion() operations on Fibonacci heap. Prerequisites: Fibonacci Heap (Introduction) Fibonacci Heap - Insertion and Union Extract_min(): We create a function for deleting the minimum node and setting the min po
12 min read
Fibonacci Heap in Python
A Fibonacci Heap is a data structure that supports the insert, minimum, extract_min, merge, decrease_key, and delete operations, all amortized efficiently. It is mainly used in the implementation of Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm. Fibonacci Heap Operations and Their Amortized Time Complexities:Insert:
4 min read
Check if a M-th fibonacci number divides N-th fibonacci number
Given two numbers M and N, the task is to check if the M-th and N-th Fibonacci numbers perfectly divide each other or not.Examples: Input: M = 3, N = 6 Output: Yes F(3) = 2, F(6) = 8 and F(6) % F(3) = 0 Input: M = 2, N = 9 Output: Yes A naive approach will be to find the N-th and M-th Fibonacci numbers and check if they are perfectly divisible or n
8 min read