| Fibonacci heap | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Type | heap | ||||||||||||||||||||||||||||||||
| Invented | 1984 | ||||||||||||||||||||||||||||||||
| Invented by | Michael L. Fredman and Robert E. Tarjan | ||||||||||||||||||||||||||||||||
| Complexities inbig O notation | |||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
Incomputer science, aFibonacci heap is adata structure forpriority queue operations, consisting of a collection ofheap-ordered trees. It has a betteramortized running time than many other priority queue data structures including thebinary heap andbinomial heap.Michael L. Fredman andRobert E. Tarjan developed Fibonacci heaps in 1984 and published them in a scientific journal in 1987. Fibonacci heaps are named after theFibonacci numbers, which are used in their running time analysis.
The amortized times of all operations on Fibonacci heaps is constant, exceptdelete-min.[1][2] Deleting an element (most often used in the special case of deleting the minimum element) works in amortized time, where is the size of the heap.[2] This means that starting from an empty data structure, any sequence ofa insert anddecrease-key operations andbdelete-min operations would take worst case time, where is the maximum heap size. In a binary or binomial heap, such a sequence of operations would take time. A Fibonacci heap is thus better than a binary or binomial heap when is smaller than by a non-constant factor. It is also possible to merge two Fibonacci heaps in constant amortized time, improving on the logarithmic merge time of a binomial heap, and improving on binary heaps which cannot handle merges efficiently.
Using Fibonacci heaps improves the asymptotic running time of algorithms which utilize priority queues. For example,Dijkstra's algorithm andPrim's algorithm can be made to run in time.

A Fibonacci heap is a collection oftrees satisfying theminimum-heap property, that is, the key of a child is always greater than or equal to the key of the parent. This implies that the minimum key is always at the root of one of the trees. Compared with binomial heaps, the structure of a Fibonacci heap is more flexible. The trees do not have a prescribed shape and in the extreme case the heap can have every element in a separate tree. This flexibility allows some operations to be executed in alazy manner, postponing the work for later operations. For example, merging heaps is done simply by concatenating the two lists of trees, and operationdecrease key sometimes cuts a node from its parent and forms a new tree.
However, at some point order needs to be introduced to the heap to achieve the desired running time. In particular, degrees of nodes (here degree means the number of direct children) are kept quite low: every node has degree at most and the size of a subtree rooted in a node of degree is at least, where is thethFibonacci number. This is achieved by the rule: at most one child can be cut off each non-root node. When a second child is cut, the node itself needs to be cut from its parent and becomes the root of a new tree (see Proof of degree bounds, below). The number of trees is decreased in the operationdelete-min, where trees are linked together.
As a result of a relaxed structure, some operations can take a long time while others are done very quickly. For theamortized running time analysis, we use thepotential method, in that we pretend that very fast operations take a little bit longer than they actually do. This additional time is then later combined and subtracted from the actual running time of slow operations. The amount of time saved for later use is measured at any given moment by a potential function. The potential of a Fibonacci heap is given by
where is the number of trees in the Fibonacci heap, and is the number of marked nodes. A node is marked if at least one of its children was cut, since this node was made a child of another node (all roots are unmarked). The amortized time for an operation is given by the sum of the actual time and times the difference in potential, wherec is a constant (chosen to match the constant factors in thebig O notation for the actual time).
Thus, the root of each tree in a heap has one unit of time stored. This unit of time can be used later to link this tree with another tree at amortized time 0. Also, each marked node has two units of time stored. One can be used to cut the node from its parent. If this happens, the node becomes a root and the second unit of time will remain stored in it as in any other root.
This sectiondoes notcite anysources. Please helpimprove this section byadding citations to reliable sources. Unsourced material may be challenged andremoved.(September 2025) (Learn how and when to remove this message) |
To allow fast deletion and concatenation, the roots of all trees are linked using a circulardoubly linked list. The children of each node are also linked using such a list. For each node, we maintain its number of children and whether the node is marked.
We maintain a pointer to the root containing the minimum key, allowing access to the minimum. This pointer must be updated during the other operations, which adds only a constant time overhead.
The merge operation simply concatenates the root lists of two heaps together and sets the minimum to be the smaller of the two heaps. This can be done in constant time, and the potential does not change, leading again to constant amortized time.
The insertion operation can be considered a special case of the merge operation, with a single node. The node is simply appended to the root list, increasing the potential by one. The amortized cost is thus still constant.


The delete-min operation does most of the work in restoring the structure of the heap. It has three phases:
Overall, the amortized time of this operation is, provided that. The proof of this is given in the following section.

If decreasing the key of a node causes it to become smaller than its parent, then it is cut from its parent, becoming a new unmarked root. If it is also less than the minimum key, then the minimum pointer is updated.
We then initiate a series ofcascading cuts, starting with the parent of. As long as the current node is marked, it is cut from its parent and made an unmarked root. Its original parent is then considered. This process stops when we reach an unmarked node. If is not a root, it is marked. In this process we introduce some number, say, of new trees. Except possibly, each of these new trees loses its original mark. The terminating node may become marked. Therefore, the change in the number of marked nodes is between of and. The resulting change in potential is. The actual time required to perform the cutting was. Hence, the amortized time is, which is constant, provided is sufficiently large.
This sectiondoes notcite anysources. Please helpimprove this section byadding citations to reliable sources. Unsourced material may be challenged andremoved.(September 2025) (Learn how and when to remove this message) |
The amortized performance of a Fibonacci heap depends on the degree (number of children) of any tree root being, where is the size of the heap. Here we show that the size of the (sub)tree rooted at any node of degree in the heap must have size at least, where is thethFibonacci number. The degree bound follows from this and the fact (easily proved by induction) that for all integers, where is thegolden ratio. We then have, and taking the log to base of both sides gives as required.
Let be an arbitrary node in a Fibonacci heap, not necessarily a root. Define to be the size of the tree rooted at (the number of descendants of, including itself). We prove by induction on the height of (the length of the longest path from to a descendant leaf) that, where is the degree of.
Base case: If has height, then, and.
Inductive case: Suppose has positive height and degree. Let be the children of, indexed in order of the times they were most recently made children of ( being the earliest and the latest), and let be their respective degrees.
We claim that for each. Just before was made a child of, were already children of, and so must have had degree at least at that time. Since trees are combined only when the degrees of their roots are equal, it must have been the case that also had degree at least at the time when it became a child of. From that time to the present, could have only lost at most one child (as guaranteed by the marking process), and so its current degree is at least. This proves the claim.
Since the heights of all the are strictly less than that of, we can apply the inductive hypothesis to them to getThe nodes and each contribute at least 1 to, and so we havewhere the last step is an identity for Fibonacci numbers. This gives the desired lower bound on.
Although Fibonacci heaps look very efficient, they have the following two drawbacks:[3]
Although the total running time of a sequence of operations starting with an empty structure is bounded by the bounds given above, some (very few) operations in the sequence can take very long to complete (in particular, delete-min has linear running time in the worst case). For this reason, Fibonacci heaps and other amortized data structures may not be appropriate forreal-time systems.
It is possible to create a data structure which has the same worst-case performance as the Fibonacci heap has amortized performance. One such structure, theBrodal queue,[5] is, in the words of the creator, "quite complicated" and "[not] applicable in practice." Invented in 2012, thestrict Fibonacci heap[6] is a simpler (compared to Brodal's) structure with the same worst-case bounds. Despite being simpler, experiments show that in practice the strict Fibonacci heap performs slower than more complicatedBrodal queue and also slower than basic Fibonacci heap.[7][8] The run-relaxed heaps of Driscoll et al. give good worst-case performance for all Fibonacci heap operations except merge.[9] Recent experimental results suggest that the Fibonacci heap is more efficient in practice than most of its later derivatives, including quake heaps, violation heaps, strict Fibonacci heaps, and rank pairing heaps, but less efficient than pairing heaps or array-based heaps.[8]
Here aretime complexities[10] of various heap data structures. The abbreviationam. indicates that the given complexity is amortized, otherwise it is a worst-case complexity. For the meaning of "O(f)" and "Θ(f)" seeBig O notation. Names of operations assume a min-heap.
| Operation | find-min | delete-min | decrease-key | insert | meld | make-heap[a] |
|---|---|---|---|---|---|---|
| Binary[10] | Θ(1) | Θ(log n) | Θ(log n) | Θ(log n) | Θ(n) | Θ(n) |
| Skew[11] | Θ(1) | O(log n)am. | O(log n)am. | O(log n)am. | O(log n)am. | Θ(n)am. |
| Leftist[12] | Θ(1) | Θ(log n) | Θ(log n) | Θ(log n) | Θ(log n) | Θ(n) |
| Binomial[10][14] | Θ(1) | Θ(log n) | Θ(log n) | Θ(1)am. | Θ(log n)[b] | Θ(n) |
| Skew binomial[15] | Θ(1) | Θ(log n) | Θ(log n) | Θ(1) | Θ(log n)[b] | Θ(n) |
| 2–3 heap[17] | Θ(1) | O(log n)am. | Θ(1) | Θ(1)am. | O(log n)[b] | Θ(n) |
| Bottom-up skew[11] | Θ(1) | O(log n)am. | O(log n)am. | Θ(1)am. | Θ(1)am. | Θ(n)am. |
| Pairing[18] | Θ(1) | O(log n)am. | o(log n)am.[c] | Θ(1) | Θ(1) | Θ(n) |
| Rank-pairing[21] | Θ(1) | O(log n)am. | Θ(1)am. | Θ(1) | Θ(1) | Θ(n) |
| Fibonacci[10][2] | Θ(1) | O(log n)am. | Θ(1)am. | Θ(1) | Θ(1) | Θ(n) |
| Strict Fibonacci[22][d] | Θ(1) | Θ(log n) | Θ(1) | Θ(1) | Θ(1) | Θ(n) |
| Brodal[23][d] | Θ(1) | Θ(log n) | Θ(1) | Θ(1) | Θ(1) | Θ(n)[24] |