Skip to content
Part IA Lent Term

Binomial Heap Amortized Analysis

Although binomial heap insert has O(logN)O(\log N) worst-case cost (cascading tree merges can ripple through many orders), its amortised cost is O(1)O(1). The potential method elegantly captures why.

The Worst Case for Insert

Inserting into a binomial heap with N=2k1N = 2^k - 1 (all tree orders present: B0,B1,,Bk1B_0, B_1, \ldots, B_{k-1}) causes cascading merges across all kk trees, costing Θ(k)=Θ(logN)\Theta(k) = \Theta(\log N). This happens only once per 2k2^k inserts — the same pattern as the binary counter.

Potential Function

Let Φ(H)=number of trees in the root list of heap H\Phi(H) = \text{number of trees in the root list of heap } H.

Properties

  • Φ(empty)=0\Phi(\text{empty}) = 0 (initial heap has no trees)
  • Φ(H)0\Phi(H) \ge 0 always (count of trees is non-negative)

Intuition

Φ\Phi measures how “spread out” the heap is. Inserting a new element (creating a B0B_0) increases Φ\Phi by 1. Merging trees reduces Φ\Phi (replacing two trees with one reduces the count by 1). Extract-min promoting children may increase Φ\Phi, but this is bounded.

Amortised Analysis of Insert

Let HH be the heap before insert, and HH' after. A single insert:

  1. Creates a new B0B_0 tree (actual cost O(1)O(1))
  2. Merges this B0B_0 with the existing root list

The merge may trigger jj tree merges (each merge replaces two trees of order ii with one tree of order i+1i+1). Actual cost: c=O(1+j)c = O(1 + j) (constant for creating B0B_0, plus O(j)O(j) for the merges).

Change in potential:

  • Initially, Φ(H)=r\Phi(H) = r (number of trees)
  • Insert creates one new tree: +1+1
  • Each merge replaces 2 trees with 1: net 1-1 per merge
  • After jj merges: Φ(H)=r+1j\Phi(H') = r + 1 - j

ΔΦ=(r+1j)r=1j\Delta\Phi = (r + 1 - j) - r = 1 - j

Amortised cost:

c^=c+ΔΦ=O(1+j)+(1j)=O(1)\hat{c} = c + \Delta\Phi = O(1 + j) + (1 - j) = O(1)

The jj terms cancel. Even though a single insert may cascade through Θ(logN)\Theta(\log N) merges in the worst case, the drop in potential (j-j) exactly compensates. Amortised insert: O(1)O(1).

Amortised Analysis of Extract-Min

Extract-min involves:

  1. Finding the minimum root: scan rr trees (cost O(r)O(r))
  2. Removing that root: O(1)O(1)
  3. Promoting its children: up to logN\log N children become new trees
  4. Re-merging: O(r+logN)O(r + \log N) work (similar to UNION)

Actual cost: c=O(r+logN)c = O(r + \log N).

Let the extracted minimum come from a BkB_k tree (root degree kk). Before: Φ=r\Phi = r. After: children become kk new trees in the root list (since BkB_k has kk children, each a Bk1,,B0B_{k-1}, \ldots, B_0). One tree (the extracted root) is removed. So net change to tree count before merging: r1+kr - 1 + k. After merging, the root list shrinks to at most logN+1\lfloor \log N \rfloor + 1.

ΔΦ(logN+1)r=O(logN)r\Delta\Phi \le (\log N + 1) - r = O(\log N) - r

Amortised cost:

c^=O(r+logN)+(O(logN)r)=O(logN)\hat{c} = O(r + \log N) + (O(\log N) - r) = O(\log N)

The rr terms cancel. Extract-min has amortised cost O(logN)O(\log N).

Comparison with Binary Heap

OperationBinary HeapBinomial Heap (worst)Binomial Heap (amortised)
InsertO(logN)O(\log N)O(logN)O(\log N)O(1)O(1)
Extract-minO(logN)O(\log N)O(logN)O(\log N)O(logN)O(\log N)
Decrease-keyO(logN)O(\log N)O(logN)O(\log N)O(logN)O(\log N)
MergeΘ(N)\Theta(N)O(logN)O(\log N)O(logN)O(\log N)

Binomial heaps match binary heaps for all operations in the worst case, excel at merge, and achieve O(1)O(1) 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. Φ\Phi = number of trees is analogous to Φ\Phi = 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 O(1)O(1) by the potential function.

Binary CounterBinomial Heap
Bit position = 2i2^iTree order kk
0 or 1 bitTree absent or present
Flip bits (carry)Merge trees (combine)
Φ\Phi = # of 1-bitsΦ\Phi = # of trees
Amortised increment: O(1)O(1)Amortised insert: O(1)O(1)

Summary

OperationWorst-caseAmortisedΔΦ\Delta\Phi
InsertO(logN)O(\log N)O(1)O(1)1j1 - j (where jj = # merges)
Extract-minO(logN)O(\log N)O(logN)O(\log N)O(logN)rO(\log N) - r (where rr = # trees)
Decrease-keyO(logN)O(\log N)O(logN)O(\log N)
MergeO(logN)O(\log N)O(logN)O(\log N)

Past Tripos: y2024p2q7, y2023p1q9.