Binomial Heap Structure and Operations
A binomial heap is a collection of heap-ordered binomial trees with at most one tree of each order. It implements a mergeable priority queue efficiently, with all core operations in time.
Structure
A binomial heap is:
- A root list: a linked list of roots of binomial trees, ordered by increasing tree degree (increasing order )
- Each tree is heap-ordered (min-heap): parent key children’s keys
- For each order , at most one tree is present
Node Attributes
Each node stores:
key,payloadparentpointer (NIL for roots)childpointer (to the leftmost/highest-degree child)siblingpointer (next sibling in the doubly-linked or singly-linked child list)degree(number of immediate children, not descendants)
The root list reuses sibling pointers of root nodes.
Binary Structure
The sizes of trees present in a binomial heap of nodes correspond exactly to the powers of 2 in the binary representation of . For , the heap contains , , and . At most trees exist.
Core Operation: Merge Two Trees
BH-MERGE(bt1, bt2): merge two binomial trees of equal degree . Make the root with the larger key the leftmost child of the root with the smaller key. Increment the degree of the surviving root. Time: .
This is the primitive that all other merge operations build upon.
Operations
Find-Minimum
Scan the root list (at most roots). Return the root with smallest key. Time: .
Merge (Destructive Union)
BH-UNION(H1, H2): merge two binomial heaps by:
- Merge the two root lists in increasing order of degree, like merging two sorted linked lists
- Scan the merged list: whenever two trees of the same degree are adjacent, merge them into a tree (using BH-MERGE). This may cascade (like binary addition with carries)
Time: , where .
This is the key advantage over binary heaps, which require to merge.
Insert
Create a single-node heap from the new element, then BH-UNION with the existing heap.
BH-INSERT(H, key, payload):
create new node n with degree 0
return BH-UNION(H, {n})
Time: (dominated by the union).
Extract-Minimum
- Find the root with minimum key (scan root list)
- Remove that root from the root list
- Reverse its child list (children are in that order; reversing gives increasing degree order)
- BH-UNION the reversed child list with the remaining root list
- Return the minimum
Time: (scan root list , promote children , BH-UNION ).
Decrease-Key
Given a pointer to a node, decrease its key. If the heap property is violated (new key < parent key), swap keys and recurse upward (bubble up), exactly as in a binary heap. Maximum number of swaps: height of the tree, which is .
Time: .
Delete
Decrease the key to , then extract-min. Time: .
Worked Example
Insert elements into an initially empty binomial heap.
| Insert | (binary) | Heap state (trees present) |
|---|---|---|
| 5 | 1 () | |
| 3 | 2 () | (merged ) |
| 7 | 3 () | |
| 1 | 4 () | (merges cascade: , plus existing ) |
| 9 | 5 () | |
| 2 | 6 () |
The tree after inserting 1 would have root 1, children (root 3 with child 5) and (7). The structure mirrors binary addition of .
Summary
| Operation | Time | Notes |
|---|---|---|
| Find-min | Scan root list | |
| Merge | Binary addition analogy | |
| Insert | Create , merge | |
| Extract-min | Remove root, promote children, re-merge | |
| Decrease-key | Bubble up; max height | |
| Delete | Decrease-key to , then extract-min |
Past Tripos: y2024p2q7, y2023p1q9.