The strength of Fibonacci heaps lies in their use of circular doubly linked lists and lazy restructuring, which enables constant-time operations and amortized complexities.
As with binary heaps, Fibonacci heaps do not support efficient search. Therefore, operations like
decrease-keyanddeleteassume direct access to the node, not just its key.In practice, an auxiliary structure (e.g. a dictionary) is often used to map keys to nodes, allowing amortised constant-time lookup at the cost of linear additional space.
Merge Operation
The merge operation combines two Fibonacci heaps, and , by joining their root lists, i.e. concatenating two circular doubly linked lists:
- Bi-directionally, connect the rightmost sibling of to the leftmost sibling of
- Bi-directionally, connect the leftmost sibling of to the rightmost sibling of .
- Set
H.minas themin(H₁.min, H₂.min)
Since root lists are circular and accessible via their minimum nodes, merging takes time.
Example Of Merging
MULTI COLUMN
Node
7(rightmost in ) is connected to node33(leftmost in ), and node4(rightmost in ) connects back to the leftmost of .H.minis updated to the smaller of the two minimums.
Insertion Operation
The insert operation adds a new node to a Fibonacci heap in time as follows:
- Access the heap via the
H.minpointer - Insert the new node into the
root_list, typically as the left sibling ofH.min - If the new node’s key is smaller than
H.min, updateH.minto point to the new node.
Insertion is done to the left for consistency, though the position is arbitrary due to the unordered nature of the root list.
Example Of Insert
Extract-Min Operation
The extract-min operation removes the node with the minimum key from the Fibonacci heap:
- Identify the minimum node via the
H.minpointer. - Remove this node from the root list via
deleteoperation. - Promote all its children to the root list in via pointer manipulation
- The children, stored in a circular doubly linked list, are spliced directly into the root list.
- This involves reconnecting:
- The leftmost child to the node left of the removed node, and
- The rightmost child to the node right of the removed node.
- Each promoted child’s
parentpointer is set tonull.
- Set
H.minto temporarily to the right sibling ofH.min - Run the
consolidateoperation to merge trees of the same degree
Before consolidation, the root list may contain multiple trees of the same degree. Afterward, the heap maintains at most one tree per degree, restoring the Fibonacci heap properties.
Example Of Extract Min
Consolidation Operation
The consolidate operation merges trees of the same degree to ensure the heap contains at most one tree of any given degree, maintaining the Fibonacci heap properties. It only executes after an extract-min operation.
- Initialise an auxiliary array
Aof size withnull, whereA[d]stores a pointer to a tree root of degreed. - Initialise
current = H.minfor node traversal andfinal = current.leftto check when a full cycle is complete. - Traverse each node in the root list, ensuring there is at most one tree of any degree
- Let
x = currentandd = current.degree - If
xis the first tree encountered with degreed(i.e.A[d] = null) then:- Set
A[d] = x - Point
currentto the next distinct node in the root list. - If
current = final, a full cycle is complete, and at most one tree of any degree exists.
- Set
- Else if another node
yhas already been encountered with degreed(A[d] != null) then:- Merge (consolidate) the two trees together, maintaining the heap-property.
- Set
A[d] = null - Point
currentto the root of the merged tree.
- Let
- Additionally, during traversal, keep track of the minimum root encountered, and update
H.min.
The amortised time complexity of consolidate and extract-min is . This, along with the space complexity of A, is due to the fact that the maximum degree of any node in a Fibonacci heap is — see proof
Example Of Consolidate
Using the above example of
extract-min, initialise an auxiliary array of size and initialisecurrent = 17andfinal = current.left = 38
The root node at
current = 17has degree , andA[1]is empty, thus setA[1] = current = 17, and pointcurrentto the right sibling24
The same applies for
current = 24andcurrent = 23. After those nodes,current = 7
The root node at
current = 7has degree , butA[0] = 23so merge (consolidate) these trees whilst maintaining min-heap property. As7 < 23, node23becomes the child of node7.Lastly set
A[0]to empty, and pointcurrentto the root of the merged tree i.e.current = 7
The same applies for the next two iterations as
current = 7has degree (A[1] = 17), and then when merged would have degree (A[2] = 24), resulting in a merged tree of degree (A[3] = null).
Continue this process until all nodes have been checked, i.e.
current = final
Decrease-Key Operation
The decrease-key operation in a Fibonacci heap reduces the key of a given node to a new, smaller value:
Case 1: When decrease-key(x -> y) does not violate the heap property i.e. parent < y
- Simply decrease the key on this node. No restructuring is required.
Case 2: When decrease-key(x -> y) does violate the heap property i.e. parent > y
- Promote the subtree rooted at
y(previouslyx) to theroot_list - Update
H.minif necessary - If
ywas marked before, unmark it after promoting. - If the
parentwas originally unmarked (i.e. hasn’t yet lost a child) mark it to indicate that it has lost a child. - Else if the
parentwas marked, repeat this promotion process with theparentnode.
The amortised complexity of decrease-key is
Note that if the parent at the root lost a child, there is no need to mark it
However, due to
extract-min/consolidate, there could appear a node in the root list that is marked.It is important that during
extract-min/consolidate, the mark is never altered as it impacts the amortised analysis.
Example of Decrease-Key (Case 1)
For the resultant tree of the consolidate example, if node
17were to be reduced to9(i.e.decrease-key(17, 9)), the parent of this node7is still less than9, so the min-heap property is maintained and no restructuring is required.
Example Of Decrease-Key (Case 2)
For the resultant tree of the consolidate example:
2A — If
46were to be reduced to15, then the min-heap property is violated as its parent24 > 15. To address this violation:
- Promote the subtree rooted at
15to theroot_list, no need to updateH.min- Since parent
24was originally unmarked (i.e., hasn’t yet lost a child), mark it.
2B — If
35were to be reduced to5, then the min-heap property is violated as its parent26 > 5. Additionally, the parent has already been marked, to address this:
- Promote the subtree rooted at
5to theroot_listand updateH.minsince5 > 7- Since parent
26was originally marked (i.e., has lost a child), then repeat this process with26.
- Promote the subtree rooted at
26to theroot_listand unmark it.- Since the parent
24was originally marked repeat this process with it.
- Promote the subtree rooted at
24to theroot_listand unmark it- Since its parent
7was originally unmarked, we would normally mark it, but as its in the root, we can let it be.
Delete Operation
The delete operation deletes some specified node from the Fibonacci Heap. It can be done simply by:
decrease-keythe node toextract-min
This removes the node in amortised time













