Fibonacci Heap Operations
Create and Peek-Min
Create returns (NIL, 0), an empty heap pointer and zero count. Peek-min returns the key and payload of the node pointed to by min_ptr, or NIL if the heap is empty. Both are .
Insert
To insert (key, payload) into heap fh:
- Create a new singleton node (left and right point to itself, parent and child NIL, marked false, degree 0).
- Call
destructive-union(fh, new_node).
Since union splices the new node into the root list and updates min_ptr if needed, insert is actual and amortised.
Destructive Union (Merge)
Given two heap handles (p1, n1) and (p2, n2):
- If either
pis NIL, return the other. - Splice the two root lists together (using
DLL-SPLICEon the circular doubly linked lists). - Set the new
min_ptrto whichever ofp1,p2has the smaller key. - Return
(winning_ptr, n1 + n2).
All steps are constant time. The splice operation is:
a.left = c,c.right = ab.right = d,d.left = b
The amortised cost is because the potential function (trees + 2×marked) adds the two separate potentials; no new trees or marks are created.
Extract-Min
This is the most expensive operation, where all deferred work is done.
Step 1 — Promote children: The minimum node is identified via min_ptr. All its children are moved to the root list. For each child, parent is set to NIL and marked to false.
Step 2 — Remove old minimum: Splice the old minimum out of the root list. Decrement n.
Step 3 — Consolidate: Create an array A[0..D(n)] initialised to NIL, where is the maximum possible degree (with , the golden ratio).
Walk around the root list. For each node t:
- If
A[t.degree]is NIL, setA[t.degree] = t. - Else, merge
twithA[t.degree]: the node with the larger key becomes the child of the node with the smaller key. The larger node is removed from the root list. The winner’s degree increments by 1. IfA[new_degree]is occupied, recursively merge. This is similar to binary addition of binomial trees.
After consolidation, at most one tree of each degree remains, so the root list has at most trees.
Step 4 — New minimum: During the walk, track the node with the smallest key; update min_ptr.
Actual cost can be (many children to process), but amortised cost is because consolidation reduces the root list from potentially many trees down to .
Decrease-Key
Given a pointer ptr_k to a node and a new key nk (must be current key):
- Set
ptr_k.key = nk. - If
ptr_kis in the root list, or its new key is its parent’s key, updatemin_ptrif needed and stop. - Otherwise: cut
ptr_kfrom its parent (via helperCHOP-OUT), splice it into the root list, and mark its parent. - If the parent was already marked, then cascading cut: chop out the parent as well, unmark it, splice it into the root list, and recurse on its parent.
CHOP-OUT handles updating the parent’s child pointer, decrementing the parent’s degree, and setting the cut node’s marked = false (since root list nodes are never marked). Amortised cost is ; actual cost is where is the height of cascading cuts, which the potential function covers.
Delete
delete(fh, ptr_k) is implemented as decrease-key(fh, ptr_k, -∞) followed by extract-min(fh). Amortised cost .
Worked Example: Extract-Min with Consolidation
Starting state: root list has trees of degrees 0, 0, 1, 0, 2, 1. Array size .
| Step | Root | A[0] | A[1] | A[2] | A[3] | Action |
|---|---|---|---|---|---|---|
| 1 | t(deg 0) | t0 | — | — | — | Store at index 0 |
| 2 | t(deg 0) | — | — | — | — | Merge with A[0] → deg 1 |
| 3 | merged(deg 1) | — | t1 | — | — | Store at index 1 |
| 4 | t(deg 1) | — | — | — | — | Merge with A[1] → deg 2 |
| 5 | merged(deg 2) | — | — | t2 | — | Store at index 2 |
| 6 | t(deg 0) | t3 | — | t2 | — | Store at index 0 |
| 7 | t(deg 2) | t3 | — | — | — | Merge with A[2] → deg 3 |
| 8 | merged(deg 3) | t3 | — | — | t3 | Store at index 3 |
Final root list: at most 4 trees (degrees 0, 0, 0, 3).
Summary
| Operation | Actual Cost | Amortised Cost |
|---|---|---|
| Create | ||
| Peek-min | ||
| Insert | ||
| Destructive-union | ||
| Extract-min | worst | |
| Decrease-key | worst | |
| Delete | — | |
| Count |