CSE3144 Β· Advanced Data Structures Β· Jul–Nov Semester 2026 Β· Lecture 18 of 36 Β· CO CSE3144.3

Binomial Heaps

Lecture 16's binary heap could insert and extract in O(log n) β€” but try to merge two of them together, and it collapses to O(n). Today: a heap built entirely out of forests of trees whose shapes come straight from Pascal's triangle, designed to merge in O(log n) flat.

Dr. Manu ShrivastavaCourse Instructor Β· Consultation Fri 2–5 PM, LHC 308F
~75 minutesSession outcome: explain heap merging and binomial tree structures
L18 Β· 00 β€” Agenda ~105 min

Today, part by part

Why binomial heaps β€” the merge gap

00–06

A binary heap can't merge two already-built heaps without an O(n) rebuild. A real emergency makes that unacceptable.

Meet Bk: the notation, and the one rule that builds it

06–11

See B0 through B3 first, then the single link that turns two Bk-1's into a Bk.

The binomial tree, defined

11–15

The same rule written formally β€” and what it forces to be true, including the binomial coefficients behind the name.

Animation: building B0 through B3

15–23

Watch the recursive definition build itself, one link at a time.

The binomial heap: a forest, one tree per bit

23–28

Min-heap-ordered trees, at most one per degree β€” literally the binary representation of n.

How it is actually stored: left-child / right-sibling

28–34

Three pointers per node, and why the child list and root list are sorted opposite ways.

Why each list is sorted the way it is

34–40

Increasing roots make UNION one pass; decreasing children make EXTRACT-MIN a single reversal.

Animation: building one hospital's queue

40–46

Three arrivals, one link β€” and the binary counter ticking 0, 1, 10, 11 alongside.

Animation: UNION β€” merging two ER queues

46–61

Two hospitals, one disaster, one merged queue β€” every link case traced.

Animation: INSERT as a binary counter

61–71

One insert with zero carries, one with a full carry chain β€” exactly like incrementing a binary number.

Animation: EXTRACT-MIN

71–76

Scan the roots to find the minimum, splice it out, reverse its children, and union the two heaps back together.

Animation: DECREASE-KEY, and DELETE

76–83

Lower a key and sift it up to the root β€” keys move, structure does not. DELETE reuses it with −∞.

Complexity, binary heap vs. binomial heap

83–86

One column changes dramatically; the rest barely move.

Advantages & limitations

86–91

What you buy with O(log n) union, and what it costs you over a plain binary heap.

Where merging heaps actually matters

91–96

Distributed systems, cluster consolidation, and a minimum-spanning-tree algorithm.

Recap & what's next

96–105

Lecture 19: Fibonacci Heaps and Amortized Efficiency.

CSE3144 β€” Lecture 18
L18 Β· 01 β€” Why binomial heaps? ~6 min

The one operation binary heaps were never built for: merge

Real-life example β€” continuing Lecture 17's ER

A regional disaster strikes. Hospital A's emergency queue and Hospital B's emergency queue β€” each already a valid, fully-built priority queue with hundreds of waiting patients β€” must become one single queue, right now, so a combined response team can serve strictly by urgency. Neither hospital has time to rebuild a queue from scratch.

Why a binary heap fails here

Lecture 16's binary heap has no efficient UNION. The only way to combine two binary heaps is to concatenate their arrays and re-run BUILD-MAX-HEAP (or BUILD-MIN-HEAP) from scratch β€” Θ(n), where n is the combined size. For two mid-sized hospitals, that could mean re-heapifying thousands of records during the exact moment speed matters most.

What we actually need

A mergeable heap: every operation a binary heap already supports (INSERT, MINIMUM, EXTRACT-MIN), plus a genuinely fast UNION. A binomial heap delivers UNION in O(log n) β€” by giving up the single-tree shape of a binary heap in favor of a small forest of trees with a very particular structure.

CSE3144 β€” Lecture 18 Β· Why binomial heaps
L18 Β· 02 β€” Meet Bk ~5 min

Before any definition β€” look at the first four, and how one is built

Everything in this lecture is written in terms of Bk. Four things to fix in your head before any definition:

The first four, drawn to the same scale
How a Bk is made: link two Bk-1's

Look again at the gallery: each tree is two copies of the one before it, one hooked under the other's root. That is the only rule there is — here it is, applied once to build that B3:

  • Nothing is rebuilt. One root becomes a child of the other, bringing its subtree along — so a link is O(1).
  • Every algorithm here is built from it. UNION, INSERT and EXTRACT-MIN do nothing else.
  • Which root ends up on top? Right now, either. No keys yet, so both choices give the identical shape. From L18·04 the heap property decides, and the smaller key stays on top.
Read the order k off the picture, three ways
ordernodesheightchildren of the root
B01 = 2000
B12 = 2111
B24 = 2222
B38 = 2333

Every column reads k straight off the tree — nodes 2k, height k, root children k. Spot any one and you know which tree you are looking at.

Two things Bk is not
  • Not a binary tree. The root of B3 has three children, and nothing limits a node to two. Binomial trees are general trees β€” that surprise catches people who arrive straight from Lecture 16.
  • Not a heap by itself. Bk is only a shape. The heap ordering (every parent ≤ its children) is an extra condition laid on top, which is what makes it a binomial heap later in L18·04.

You now know what Bk looks like and how one is built. The next slide writes that same rule down formally and works out what follows from it.

CSE3144 β€” Lecture 18 Β· Bk notation
L18 Β· 02a β€” The binomial tree, defined ~4 min

Defined by one rule: link two Bk-1 trees together

Same rule you just watched on the previous slide β€” now written down properly, so we can work out what it forces to be true. Everything below is still shape only: no keys, no heap ordering.

The recursive definition

B0 is a single node. Bk is formed by taking two copies of Bk-1 and linking them: the root of one becomes the new leftmost child of the root of the other. That's the entire definition β€” every other property falls out of it.

What falls out of it (verified, not just asserted)
  • Bk has exactly 2k nodes (two copies of a 2k-1-node tree).
  • Bk has height exactly k.
  • Bk has exactly C(k,i) nodes at depth i β€” the binomial coefficients, which is exactly where the name comes from.
  • The root of Bk has degree k, and β€” left to right β€” its children are the roots of Bk-1, Bk-2, …, B0.
Why "binomial" β€” check row 3 against Pascal's triangle

Count B3's nodes by depth back in the L18·02 gallery: 1, 3, 3, 1. Those are exactly C(3,0), C(3,1), C(3,2), C(3,3) β€” a row of Pascal's triangle. The same holds at every order:

treenodes at depth 0, 1, 2, 3total
B11, 12
B21, 2, 14
B31, 3, 3, 18

The rows sum to 2k, exactly as ∑i C(k,i) = 2k says they must. The name is descriptive, not decorative.

CSE3144 β€” Lecture 18 Β· Binomial tree definition
L18 Β· 03 β€” Animation: building B0 through B3 ~8 min

Watch the recursive definition build itself

You have seen one link close up (L18·02) and the rule stated formally (L18·02a). Now watch the whole ladder built from nothing: B0 → B1 → B2 → B3, where every step is exactly one link β€” take two identical trees, make one root the new leftmost child of the other.

Shape only β€” no heap property yet

Everything from L18·02 to here is about shape alone. That is why every node is drawn as a bare : there are no keys in these trees, so there is nothing to compare and no heap ordering to check or maintain. Bk at this point is a pattern, not a data structure holding anything. When two trees are linked below, "which root stays on top" is genuinely arbitrary — both choices give the identical shape. Keys, the heap property (every parent ≤ its children), and therefore a real rule for who wins a link, all arrive in L18·04, when these shapes start carrying data.

Interactive β€” B0 → B1 → B2 → B3
CSE3144 β€” Lecture 18 Β· Building binomial trees
L18 Β· 04 β€” The binomial heap ~5 min

A forest of binomial trees β€” one tree per 1-bit of n

Two properties, together
  • Min-heap-ordered: every binomial tree in the heap obeys the min-heap property β€” a node's key is never less than its parent's.
  • At most one tree per degree: for any k, the heap contains at most one Bk.
The binary-number connection

Write n in binary. Bit i is 1 exactly when the heap contains a Bi. A heap of 13 patients (binary 1101) is a B3 (8 nodes) + a B2 (4 nodes) + a B0 (1 node) β€” never two trees of the same degree, exactly like a binary digit is never anything but 0 or 1.

One thing this forest cannot do: live in an array

Lecture 16's binary heap needed no pointers at all β€” children of index i sat at 2i and 2i+1. That trick only worked because the tree was complete, so the indices were dense with no gaps. A binomial heap is a forest of differently-shaped trees whose roots have wildly different degrees, so no index formula exists. It has to be built from real pointers β€” which is what the next slide shows, node by node.

CSE3144 β€” Lecture 18 Β· Binomial heap definition
L18 Β· 04a β€” How it is actually stored ~6 min

Three pointers per node β€” whether it has 1 child or 20

The root of Bk has k children, and k changes from tree to tree. Giving every node a variable-length array of children would mean a separate allocation per node. The standard fix β€” left-child / right-sibling β€” avoids that entirely: each node stores only its leftmost child plus its next sibling, so a node's children become a linked list and every node is the same fixed size.

What one node holds
parent→ up to its parent
keythe priority value
degreehow many children it has
child→ its leftmost child only
sibling→ the next sibling to its right

Five fields, fixed size, forever. A root with 20 children still stores exactly one child pointer β€” the other 19 are reached by hopping along sibling.

So "visit all children of x" is a walk, not an index
y = x.child
while y ≠ NIL:
    visit y
    y = y.sibling

Compare with Lecture 16, where the same job was A[2i] and A[2i+1] β€” two array reads, no pointer chasing. This is the concrete cost of giving up the single complete tree: more memory per node, and worse cache locality.

A real B2, drawn as a tree and as the pointers that actually exist

A min-heap-ordered B2: every parent's key is ≤ its children's (4 ≤ 8, 4 ≤ 5, 8 ≤ 9). The picture shows 4 with two children β€” but no node ever stores "two children".

What is really in memory:

nodeparentdegreechildsibling
4 (root)NIL28next root
84195
540NILNIL
980NILNIL

Read row 1: node 4 points only at 8. To find its second child you go 4.child = 8, then 8.sibling = 5. The children of 4 are the chain 8 → 5 → NIL.

Inside one tree: the children come out in decreasing degree

The B2 above has only two children, so the pattern is easy to miss. Here is a B3, where it is unmistakable β€” read its root's children left to right:

Following 12.child and then the sibling pointers:

12.child 15deg 2 14deg 1 40deg 0 NIL

Degrees 2, 1, 0 β€” strictly decreasing, and every order below 3 present exactly once. That is the L18·02a property, now visible as an actual pointer chain.

The root list β€” the heap itself is just a pointer to this chain

The trees are not held in an array either. Their roots are strung together with the very same sibling field, forming one linked list. Here is the n = 13 heap from the last slide (11012 → B3 + B2 + B0):

head[H] B0degree 0 · 1 node B2degree 2 · 4 nodes B3degree 3 · 8 nodes NIL

Degrees strictly increase along the root list β€” 0, 2, 3 β€” with degree 1 simply absent, because bit 1 of 13 is 0. The whole heap is a single pointer, head[H], to the front of this chain. Total nodes 1 + 4 + 8 = 13.

The gotcha: the two lists are sorted opposite ways
listorderexample
a node's child listdecreasing degreeB3's root → B2, B1, B0
the root listincreasing degreeB0, B2, B3

This is not an inconsistency β€” each ordering is chosen for the operation that depends on it, as below.

Neither order is arbitrary

Each direction is chosen for the one operation that depends on it: the increasing root list is what lets UNION run in a single linear pass, and the decreasing child list is what lets EXTRACT-MIN hand back a legal heap without any repair work. Both are worth seeing drawn out β€” that is the next slide.

CSE3144 β€” Lecture 18 Β· Representation
L18 Β· 04b β€” Why each list is sorted the way it is ~6 min

Two orderings, two operations, no coincidence

Sorting choices in a data structure are almost never aesthetic. Here each one exists to make a specific operation cheap β€” and if you flipped either, that operation would lose its O(log n).

1 · Root list increasing — so two heaps merge in one pass

Merge a heap of 5 patients with one of 3. In binary that is 101 + 011, and the root lists are already sorted by degree:

H1 · n=5 · 101
head B0deg 0 B2deg 2 NIL
H2 · n=3 · 011
head B0deg 0 B1deg 1 NIL
walk both lists once, always taking the smaller degree — the merge step of mergesort
merged
head B0deg 0 B0deg 0 B1deg 1 B2deg 2 NIL

Here is the whole payoff: because both inputs were sorted, the two degree-0 trees came out next to each other (highlighted). Duplicates are always neighbours, so the linking sweep never has to search for a partner β€” it just checks the node in front of it. Two B0's link into a B1, which collides with the B1 already there and links into a B2, which collides with the B2 and links into a B3. Final: 5 + 3 = 8 = 1000 — one tree, exactly as binary addition predicts.

Flip the ordering and this dies. The root list is a plain linked list — no random access, no binary search — so finding anything in it means walking it. What saves us is that the list is short: a heap on n nodes has at most ⌊lg n⌋+1 trees, so the list is only O(log n) long. Sorted, equal degrees are adjacent and each partner is found in O(1) — just check x.sibling. Unsorted, a partner could be anywhere, so each one costs a full O(log n) walk — once per root, and UNION degrades to O(log² n).

2 · Child list decreasing — so a deleted root leaves a heap behind

EXTRACT-MIN removes a whole root — specifically the root holding the smallest key, which has to be found by scanning the root list, since that list is ordered by degree and says nothing about keys. Whichever tree wins, the same thing happens to its children. Take a B3 as the illustration: remove its root and you are left holding its children, which by the definition in L18·02a are stored in decreasing order:

children of B3's root, as stored
B2deg 2 B1deg 1 B0deg 0 NIL
decreasing — not a legal root list. Reverse the chain (one pass, O(log n) pointers)
after reversing
head B0deg 0 B1deg 1 B2deg 2 NIL

That is now a legal binomial heap β€” increasing degrees, one tree per order β€” obtained by nothing but reversing a linked list. No rebuilding, no re-heapifying. It can be UNION-ed straight back into what remains.

Check the arithmetic β€” it had to come out this way

Removing the root of a B3 leaves 8 − 1 = 7 nodes, and the leftovers are B2 + B1 + B0 = 4 + 2 + 1 = 7. βœ“

In binary, 7 = 111 β€” every bit set. That is not a coincidence: 2k − 1 is always k ones, which says the leftovers must be exactly one tree of every order from k−1 down to 0. This is the same "no gaps inside a tree" property from L18·02a, seen from the other side β€” and it is precisely why the leftovers are always a valid heap.

The two orderings, side by side
listorderwhat it buys — and what flipping it would cost
root listincreasingUNION merges in one linear pass, duplicates landing adjacent.
Flipped: every link has to be searched for → O(log² n).
child listdecreasingEXTRACT-MIN reverses once and holds a legal heap.
Flipped: an extra sort or reversal on every extract.

You will watch both of these run for real: the merge-and-carry sweep in L18·06, and the detach-reverse-union in L18·08.

CSE3144 β€” Lecture 18 Β· Why the orderings
L18 Β· 05 β€” Animation: building one queue ~6 min

Where these queues come from: one patient at a time

The next slide merges two hospital queues. Neither one appeared fully formed — each was built by ordinary arrivals, one INSERT at a time. Watch Hospital A's queue grow from empty, and notice that every arrival is the same two moves: wrap the patient in a one-node heap, then fold it in, linking whenever two trees of equal degree meet.

Interactive — Hospital A takes three patients: 2, then 6, then 9
Hospital B, built exactly the same way

Arrivals 7, then 8, then 4. Same story: 7 and 8 collide at degree 0 and link (7 ≤ 8, so 7 takes the root), then 4 finds the degree-0 slot empty and simply joins the root list. Three patients, binary 11.

These two queues — Hospital A and Hospital B — are precisely the two inputs merged on the next slide.

Every insert is +1 in binary
after arrivalnbinarytrees presentcarry?
00none
211B0no
6210B1yes
9311B0, B1no

Read the binary column downward: 0, 1, 10, 11 — a counter incrementing. A carry in the counter is a link in the heap, and the two happen at exactly the same moments. L18·07 pushes this further with a triple cascade.

CSE3144 — Lecture 18 · Building a queue
L18 Β· 06 β€” Animation: UNION ~15 min

Two hospitals, one disaster, one merged queue

Hospital A's queue: B0={9}, B1={2,6} (3 patients). Hospital B's queue: B0={4}, B1={7,8} (3 patients). UNION(H1,H2) has two phases: MERGE the two root lists by degree, then LINK equal-degree roots until at most one tree of each degree remains β€” exactly like adding 011 + 011 in binary.

Read this first — the four cases the linking sweep chooses between

Phase 2 walks the merged root list with two pointers, x and next-x, and at each position takes exactly one of four branches. The step commentary below names them, so it is worth having them in front of you:

casewhenwhat it does
1degree(x) ≠ degree(next-x)nothing to link here — just advance the pointers
2three roots in a row share a degreeadvance without linking, deferring the collision to the later pair
3exactly two share a degree, and key(x) ≤ key(next-x)x stays the root; next-x is linked underneath it
4exactly two share a degree, and key(x) > key(next-x)next-x becomes the root; x is linked underneath it
  • Cases 3 and 4 are the same link with the winner swapped — the smaller key always ends up on top. They are written separately only because of pointer bookkeeping: in Case 3 x keeps its place in the root list, while in Case 4 x is spliced out and the traversal continues from next-x.
  • Cases 1 and 2 do not link at all — they only move the pointers along.
  • Because both input heaps held at most one tree per degree, the merged list can never contain four roots of the same degree, which is why three cases of collision (2, 3, 4) are enough.

In this particular run you will see Cases 2, 3 and 4. Case 1 never fires here, because after the merge every adjacent pair the sweep examines happens to have equal degree — a reminder that the cases are branches of one loop, not four stages that all must occur.

Interactive β€” BINOMIAL-HEAP-UNION(H1, H2)
CSE3144 β€” Lecture 18 Β· UNION animation
L18 Β· 07 β€” Animation: INSERT as a binary counter ~10 min

One insert with zero carries, one with a full carry chain

INSERT(H,x) is just UNION(H, {x}) β€” a singleton heap merged in. Starting from the merged 6-patient queue (binary 110), watch two arrivals: patient priority 1 (no cascade: 110+1=111) and then patient priority 0 (a full triple cascade: 111+1=1000).

Interactive β€” INSERT(1), then INSERT(0)
CSE3144 β€” Lecture 18 Β· INSERT animation
L18 Β· 08 β€” Animation: EXTRACT-MIN ~5 min

Scan the roots, remove the winner, reverse, union

A 13-patient queue — B0, B2, B3. Two questions the shape alone cannot answer: which root gets removed, and what happens to the rest afterwards. The root list is sorted by degree, not by key, so the minimum has to be hunted for — and here it is deliberately in the middle tree, so neither "the first root" nor "the biggest tree" is the answer.

Interactive β€” BINOMIAL-HEAP-EXTRACT-MIN(H)
CSE3144 β€” Lecture 18 Β· EXTRACT-MIN animation
L18 Β· 08a β€” Animation: DECREASE-KEY ~7 min

A patient deteriorates: raise their priority, walk it up

A patient already in the queue gets worse, so their key must drop. Continuing with the 12-patient heap left by the last slide, we decrease the deepest node of the B3 — key 22 — to 5. Watch what moves and, more importantly, what does not.

Interactive β€” BINOMIAL-HEAP-DECREASE-KEY(H, x, 5)
The algorithm β€” and why it is O(log n)
DECREASE-KEY(H, x, k)
  if k > x.key: error
  x.key = k
  y = x;  z = y.parent
  while z ≠ NIL and y.key < z.key:
      swap y.key ↔ z.key
      y = z;  z = y.parent
  • Keys move, nodes do not. Only key fields are swapped — every child, sibling and degree is untouched, so the tree stays a valid B3 and the root list never changes.
  • The loop is bounded by height. It walks x up to its root, and a Bk has height k ≤ ⌊lg n⌋ — so at most O(log n) swaps. That is the "sift-up path" the complexity table refers to.
  • This is what parent is for. It is the only operation in this lecture that travels upward; L18·04a's fifth pointer field finally earns its place.
Two things students always ask

1. How do you find x in the first place?

You do not search for it — that would be O(n) and would wreck the bound. DECREASE-KEY takes a pointer to the node. Real users keep a handle: Dijkstra and Prim hold a vertex → node array, so relaxing an edge jumps straight to the right node.

2. What about DELETE?

It reuses what you already have — no new machinery:

DELETE(H, x)
  DECREASE-KEY(H, x, −∞)
  EXTRACT-MIN(H)

Drive the key below every other key and it sifts all the way to the root of its tree; being the minimum, EXTRACT-MIN then removes it. Two O(log n) steps, so DELETE is O(log n) as well.

Why Lecture 19 exists

Nothing above is wasteful — yet DECREASE-KEY is the operation that keeps binomial heaps out of the top spot for Dijkstra and Prim, where edge relaxations vastly outnumber extractions. Every relaxation pays an O(log n) walk up the tree. Fibonacci heaps attack exactly this: instead of sifting up, they cut the node out and drop it into the root list, deferring all the tidying — O(1) amortized. That single change is the subject of the next lecture.

CSE3144 β€” Lecture 18 Β· DECREASE-KEY
L18 Β· 09 β€” Complexity: binary heap vs. binomial heap ~3 min

One column changes dramatically; the rest barely move

OperationBinary heap (worst-case)Binomial heap (worst-case)Fibonacci heap (amortized) β€” Lecture 19
MAKE-HEAPΘ(1)Θ(1)Θ(1)
INSERTΘ(log n)O(log n)Θ(1)
MINIMUMΘ(1)O(log n)Θ(1)
EXTRACT-MINΘ(log n)Θ(log n)O(log n)
UNIONΘ(n)O(log n)Θ(1)
DECREASE-KEYΘ(log n)Θ(log n)Θ(1)
DELETEΘ(log n)Θ(log n)O(log n)
Where those costs come from β€” every shape property from L18·02a, cashed in

Each property of Bk is load-bearing for exactly one column above. Now that you have watched all three operations run, they can be lined up:

property of Bkwhat it buysseen in
root has degree klets UNION spot two trees of the same order and link them β€” the carry stepL18·06, L18·07
children are roots of Bk-1, …, B0deleting a root leaves trees of distinct orders β€” already a legal heap, so no repair is neededL18·08
height = kbounds every sift-up path, which is what makes DECREASE-KEY and DELETE O(log n) — watched in L18·08athe table above
2k nodesone tree per order mirrors one binary digit per place β€” so at most ⌊lg n⌋+1 trees ever existL18·04, L18·07

Notice the one row that is a genuine loss: MINIMUM. A binary heap reads it from A[1] in Θ(1); a binomial heap must scan every root, and there are O(log n) of them. That is the price of being a forest instead of one tree β€” and against Θ(n) UNION, it is a bargain.

n = total nodes across the heap(s) involved. Every binomial-heap number above was exercised today: UNION took 4 root comparisons and 2 links for two 3-node heaps; INSERT ranged from 0 links (best case) to 3 cascading links (worst case, still O(log n)).

CSE3144 β€” Lecture 18 Β· Complexity
L18 Β· 09a β€” Advantages & limitations ~5 min

O(log n) merging β€” and what it costs to get there

Advantages
  • UNION in O(log n) β€” the headline improvement over a binary heap's Θ(n), verified today on two real 3-node heaps.
  • Every other core operation (INSERT, MINIMUM, EXTRACT-MIN, DECREASE-KEY, DELETE) still runs in O(log n) or better β€” no regression versus a binary heap.
  • A genuinely clean mental model: a binomial heap behaves exactly like a binary counter β€” INSERT is "add 1," UNION is "binary addition," carries and all.
  • INSERT is O(log n) worst case but O(1) amortized β€” most insertions cause zero cascading links, exactly like most binary-counter increments flip only the lowest bit.
Limitations
  • More overhead per node. Parent/child/sibling/degree pointers cost real memory, versus a binary heap's implicit array indices β€” and pointer-chasing is less cache-friendly than sequential array access.
  • More complex to implement correctly. The four linking cases in UNION (Lecture 18's own flagship animation) are meaningfully trickier than a binary heap's single sift-up/sift-down rule.
  • No benefit if you never need UNION. A plain binary heap remains simpler, more cache-friendly, and equally fast for insert/extract-min alone β€” don't reach for a binomial heap unless merging is actually part of your workload.
  • Still not the best at DECREASE-KEY-heavy workloads (e.g. Dijkstra's algorithm with many edge relaxations) β€” Lecture 19's Fibonacci heap improves exactly that operation, from O(log n) to O(1) amortized.
CSE3144 β€” Lecture 18 Β· Trade-offs
L18 Β· 10 β€” Where merging heaps actually matters ~5 min

Not a hypothetical exercise β€” merging comes up constantly

Emergency response (today's example)

Combining two independently-run triage queues β€” hospitals, disaster-response teams, or field units β€” into one, fast, without ever rebuilding from scratch.

Distributed job schedulers

When two compute clusters or worker pools are consolidated (auto-scaling merges, data-center failover), their pending-job priority queues need to become one queue without an expensive full re-sort.

Minimum spanning trees

A classic MST algorithm variant maintains one edge-priority-queue per connected component and repeatedly extracts the cheapest edge; whenever two components merge, their two queues must merge too β€” exactly a binomial-heap UNION, once per merge.

Event-driven simulation at scale

Large distributed simulations run independent event queues per node; periodically synchronizing (merging) them into a global queue benefits directly from fast UNION.

Version-control / CRDT merges

Systems that maintain ordered pending-operation queues on independent replicas, then merge after a network partition heals, face the same "combine two already-valid structures cheaply" problem.

Leaderboard / matchmaking consolidation

Regional game servers merging after a scheduled maintenance window need to combine independent priority-ranked matchmaking queues into one.

CSE3144 β€” Lecture 18 Β· Real-world use
L18 Β· 11 β€” Recap & what's next ~9 min

A forest that merges like a binary counter adds

Lecture 19 β€” next

Fibonacci Heaps and Amortized Efficiency

Binomial heaps still cost O(log n) for DECREASE-KEY. Fibonacci heaps get it down to O(1) amortized β€” by being lazier about when they actually fix the structure.

Homework β€” bring to Lecture 19
  • Draw B4 by hand from the recursive definition (two B3s linked). Confirm it has 16 nodes, height 4, and that depth-2 has exactly C(4,2)=6 nodes.
  • Build two small binomial heaps of your own (e.g. 4 nodes and 5 nodes) and trace BINOMIAL-HEAP-UNION by hand. Which of the four cases does each step trigger?
  • Starting from a 7-node binomial heap (binary 111), trace 1 more INSERT by hand. Confirm you get a single B3 (binary 1000) with exactly 3 cascading links.
  • In 3–4 sentences: why is INSERT O(log n) worst-case but O(1) amortized? Connect this explicitly to the binary-counter argument from Lecture 3's amortized analysis.
CSE3144 β€” Lecture 18

Questions?

Dr. Manu Shrivastava β€” LHC 308F β€” Friday 2:00–5:00 PM

Next: Lecture 19 β€” Fibonacci Heaps and Amortized Efficiency.