Binomial Heap Amortized Analysis
Although binomial heap insert has worst-case cost (cascading tree merges can ripple through many orders), its amortised cost is . The potential method elegantly captures why.
The Worst Case for Insert
Inserting into a binomial heap with (all tree orders present: ) causes cascading merges across all trees, costing . This happens only once per inserts — the same pattern as the binary counter.
Potential Function
Let .
Properties
- (initial heap has no trees)
- always (count of trees is non-negative)
Intuition
measures how “spread out” the heap is. Inserting a new element (creating a ) increases by 1. Merging trees reduces (replacing two trees with one reduces the count by 1). Extract-min promoting children may increase , but this is bounded.
Amortised Analysis of Insert
Let be the heap before insert, and after. A single insert:
- Creates a new tree (actual cost )
- Merges this with the existing root list
The merge may trigger tree merges (each merge replaces two trees of order with one tree of order ). Actual cost: (constant for creating , plus for the merges).
Change in potential:
- Initially, (number of trees)
- Insert creates one new tree:
- Each merge replaces 2 trees with 1: net per merge
- After merges:
Amortised cost:
The terms cancel. Even though a single insert may cascade through merges in the worst case, the drop in potential () exactly compensates. Amortised insert: .
Amortised Analysis of Extract-Min
Extract-min involves:
- Finding the minimum root: scan trees (cost )
- Removing that root:
- Promoting its children: up to children become new trees
- Re-merging: work (similar to UNION)
Actual cost: .
Let the extracted minimum come from a tree (root degree ). Before: . After: children become new trees in the root list (since has children, each a ). One tree (the extracted root) is removed. So net change to tree count before merging: . After merging, the root list shrinks to at most .
Amortised cost:
The terms cancel. Extract-min has amortised cost .
Comparison with Binary Heap
| Operation | Binary Heap | Binomial Heap (worst) | Binomial Heap (amortised) |
|---|---|---|---|
| Insert | |||
| Extract-min | |||
| Decrease-key | |||
| Merge |
Binomial heaps match binary heaps for all operations in the worst case, excel at merge, and achieve amortised insert. This makes them suitable for algorithms with many inserts relative to extract-min calls (though Fibonacci heaps improve further; see the Fibonacci heap discussion in the full course).
Connection to the Binary Counter
The binomial heap insert analysis mirrors the binary counter exactly. = number of trees is analogous to = number of 1-bits. The cascading merges correspond to cascading bit flips. In both cases, the expensive operation (many merges / many flips) is amortised to by the potential function.
| Binary Counter | Binomial Heap |
|---|---|
| Bit position = | Tree order |
| 0 or 1 bit | Tree absent or present |
| Flip bits (carry) | Merge trees (combine) |
| = # of 1-bits | = # of trees |
| Amortised increment: | Amortised insert: |
Summary
| Operation | Worst-case | Amortised | |
|---|---|---|---|
| Insert | (where = # merges) | ||
| Extract-min | (where = # trees) | ||
| Decrease-key | — | ||
| Merge | — |
Past Tripos: y2024p2q7, y2023p1q9.