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

Comparative Study of Heap Structures

Binary, Binomial, Fibonacci, and Pairing heaps all answer the same question β€” "give me the smallest, fast" β€” with four completely different bets about when to do the work. Today we run the identical operation sequence through all four, side by side, and watch the bets pay off differently.

Dr. Manu ShrivastavaCourse Instructor Β· Consultation Fri 2–5 PM, LHC 308F
~90 minutesSession outcome: compare Binary, Binomial, Fibonacci, and Pairing heaps
L21 Β· 00 β€” Agenda ~90 min

One race, four contestants

Why compare now?

00–08

Four lectures (16, 18, 19, 20) built four structures for one job. Today: put them next to each other.

Structural recap, side by side

08–18

Array vs. forest-of-trees vs. lazy-forest vs. single-multiway-tree β€” four different answers to "how do I hold a set of keys?"

The four comparison axes

18–28

Eagerness, degree bound, merge cost, bookkeeping overhead β€” the real design variables underneath the Big-O.

The grand complexity table

28–38

Every operation, all four structures, one table β€” including the one bound that's still an open problem.

Animation: the same-sequence race

38–68

Insert 2, 8, 4, 15, 10 β†’ merge β†’ decrease-key β†’ extract-min. Applied to all four heaps at once. Every operation, every structure, nothing skipped.

Final tally β€” and an honest caveat

68–74

Who did the least work on this one small example β€” and why that is not a proof of anything asymptotic.

Decision guide

74–82

Bounded array PQ, merge-heavy workload, decrease-key-heavy graph algorithm, need-it-simple-and-fast β€” which heap, and why.

Where each one actually runs

82–88

Standard libraries, graph engines, and why the "theoretical champion" is rarely the one deployed.

Recap & what's next

88–90

Lecture 22: Introduction to Spatial Data Structures.

CSE3144 β€” Lecture 21
L21 Β· 01 β€” Why compare now? ~8 min

Four lectures, one job: hold a set, answer "what's smallest?" fast

The shared contract

Every structure in Lectures 16–20 implements the same abstract priority queue: INSERT, FIND-MIN, EXTRACT-MIN, and (for three of the four) UNION/MERGE and DECREASE-KEY. If the interface is identical, the only thing left to compare is how each structure pays for that interface β€” and that's a genuinely different story for each one.

The recurring lesson

Each new heap in this course existed to fix exactly one weakness of the previous one: Binary heap can't merge in less than O(n) → Binomial heap fixes merge to O(log n) by using a forest, not one array. Binomial heap's decrease-key is still O(log n) → Fibonacci heap fixes it to O(1) amortized by going lazy. Fibonacci heap's constant factors are painful in practice → Pairing heap fixes that by throwing away every bookkeeping field except three pointers.

Today's method

Rather than compare asymptotics in the abstract, we build all four structures from empty, feed the exact same sequence of operations into each one, and watch what actually happens β€” structurally and in terms of real pointer work β€” at every single step. This mirrors Lecture 15's dual-panel AVL-vs-Red-Black comparison, extended to four panels.

CSE3144 β€” Lecture 21 Β· Why compare
L21 Β· 02 β€” Structural recap, side by side ~10 min

Four different answers to "how do I hold a set of keys?"

CSE3144 β€” Lecture 21 Β· Structural recap
L21 Β· 03 β€” The four comparison axes ~10 min

The real design variables underneath the Big-O

Axis 1 β€” Eagerness

Binary heap restores the heap property immediately after every operation (eager). Binomial heap is also eager but only within a UNION/consolidation call. Fibonacci heap is deliberately lazy β€” it defers all structural cleanup to the next EXTRACT-MIN. Pairing heap is lazy in the same spirit but pays as it goes on every MELD, with cleanup concentrated at REMOVE-MIN.

Axis 2 β€” Shape: one tree, or many?

Binary heap: one complete binary tree, stored flat in an array. Binomial heap: a forest of binomial trees, at most one per degree β€” a direct mirror of binary counter bits. Fibonacci heap: an unordered forest of arbitrary-shaped trees, root list circular and doubly linked. Pairing heap: a single unordered multiway tree β€” no forest at all.

Axis 3 β€” What MERGE costs

This is the single biggest structural fork in the family. Binary heap's array layout makes merging two heaps fundamentally rebuild-from-scratch work: O(n). The other three all store multiple independent trees (or a splice-friendly single tree), so merging is just relinking a constant or logarithmic number of root pointers: O(log n) for Binomial, O(1) for Fibonacci and Pairing.

Axis 4 β€” Per-node bookkeeping

Binary heap: zero extra fields (position is implicit in the array index). Binomial heap: parent, child, sibling, degree. Fibonacci heap: parent, child, left, right, degree, and a mark bit β€” the richest node of the four, and the reason its constant factors are the worst. Pairing heap: child, left, right β€” no parent, degree, or mark field, thanks to the "first child's left pointer is the parent" trick from Lecture 20.

CSE3144 β€” Lecture 21 Β· Comparison axes
L21 Β· 04 β€” The grand complexity table ~10 min

Every operation, all four structures, one table

OperationBinary heap (worst-case)Binomial heap (worst-case)Fibonacci heap (amortized)Pairing heap (amortized)
MAKE-HEAPΘ(1)Θ(1)Θ(1)Θ(1)
INSERTΘ(log n)O(log n)Θ(1)O(1)
FIND-MINΘ(1)O(log n)Θ(1)O(1)
EXTRACT-MINΘ(log n)Θ(log n)O(log n)O(log n) β€” proven
UNION / MERGEΘ(n)O(log n)Θ(1)O(1)
DECREASE-KEYΘ(log n)Θ(log n)Θ(1)conjectured O(1); best proven bound is looser β€” a genuine open problem
DELETEΘ(log n)Θ(log n)O(log n)O(log n) β€” proven, same machinery as EXTRACT-MIN

Read this table as a story, not just a lookup: Binomial heap exists purely to fix Binary heap's bolded UNION row. Fibonacci heap exists purely to fix DECREASE-KEY from O(log n) to O(1). Pairing heap keeps Fibonacci's practical speed but honestly cannot yet prove the same DECREASE-KEY bound β€” the one asterisk in an otherwise-solid table, exactly as Lecture 20 flagged it.

CSE3144 β€” Lecture 21 Β· Grand complexity table
L21 Β· 05 β€” Animation: the same-sequence race ~30 min

Insert 2, 8, 4, 15, 10 β†’ merge in {6, 3} β†’ decrease-key 15→1 β†’ extract-min

Watch all four structures respond to the identical sequence of eight operations, one operation per step β€” nothing merged into a single step. Each structure was built completely independently and hand-verified; every one arrives at the same underlying key set after each shared operation, but by very different internal work. A running "structural operations so far" counter tracks pointer-rewires (swaps or links) for each heap.

Interactive β€” same sequence, four heaps
CSE3144 β€” Lecture 21 Β· The same-sequence race
L21 Β· 06 β€” Final tally β€” and an honest caveat ~6 min

Fewest total pointer-rewires: Fibonacci heap, by a wide margin. That is not the whole story.

StructureTotal structural ops across all 8 operationsWhere the cost concentrated
Binary heap4 swaps (+ an O(n)-touch rebuild on merge)The merge step, structurally β€” every non-leaf position had to be inspected even though only 1 swap resulted.
Binomial heap7 linksSpread evenly: 3 during inserts (the "carry" at insert 15), 2 at decrease-key, 2 at the extract-min consolidation.
Fibonacci heap4 linksAll of it deferred to the one EXTRACT-MIN β€” every insert, the merge, and this particular decrease-key cost exactly zero, because the node happened to already be a root.
Pairing heap7 linksSpread across every operation β€” pairing heap never defers, it pays a small O(1) cost immediately, every time.
Why this is not a proof of anything

This is one small example with n = 7 at its largest. Fibonacci heap's near-zero count here is partly luck: the decrease-key target happened to already be a root, so no cut was needed at all β€” with a different heap history (one where that node were buried three levels deep and marked), Fibonacci heap would show real cut-and-cascade activity too. Binary heap's low swap count similarly hides that its merge step touches Θ(n) positions regardless of how many actually move β€” a cost that gets dramatically worse as n grows, unlike the other three. The complexity table in Section 04 is the trustworthy source for what happens at scale; this animation's job was only to make the mechanics tangible enough to trust that table.

CSE3144 β€” Lecture 21 Β· Final tally
L21 Β· 07 β€” Decision guide ~8 min

Which heap, and why

You need a simple, bounded, in-memory priority queue

Use a binary heap. No merge, no decrease-key-heavy workload, cache-friendly array layout, smallest constant factors of the four. This is what almost every standard library's default priority queue actually is.

You need to repeatedly merge whole queues

Use a binomial heap if you specifically want a clean, well-understood, worst-case O(log n) merge with a textbook binary-counter analogy (Lecture 18's hospital-merger scenario) β€” or a pairing heap if you want O(1) actual-cost merges and don't need the binomial heap's more rigid degree structure.

You're running Dijkstra's or Prim's algorithm at scale, and it's decrease-key-bound

Fibonacci heap is the textbook answer β€” it is the reason Dijkstra's algorithm has an O(E + V log V) bound at all. But per Lecture 20's honest caveat: most production graph libraries use a pairing heap or even a plain binary heap here, because Fibonacci heap's constant-factor overhead rarely pays off before graphs get very large.

You want the closest thing to "just works, fast, in practice"

Use a pairing heap. It is the structure real systems reach for when they need merge and decrease-key to be fast without paying Fibonacci heap's per-node bookkeeping cost β€” accepting, in exchange, that DECREASE-KEY's tightest amortized bound remains an open research question rather than a closed proof.

CSE3144 β€” Lecture 21 Β· Decision guide
L21 Β· 08 β€” Where each one actually runs ~6 min

The theoretical champion is rarely the one deployed

Binary heap

C++'s std::priority_queue and Python's heapq module are both plain array-based binary heaps β€” by far the most-used priority queue implementation in existence, precisely because most real workloads never need an efficient merge.

Binomial heap

Common in purely functional programming languages (Haskell, Standard ML), where the forest-of-trees structure supports efficient persistent (immutable, structure-sharing) merges β€” a natural fit for a language where nothing is mutated in place.

Fibonacci heap

Mostly appears in algorithms textbooks and research code as the structure that gives Dijkstra's, Prim's, and network-flow algorithms their best theoretical bounds. Rarely the production implementation, exactly as flagged in Lecture 19 β€” the per-node overhead outweighs the asymptotic win at everyday graph sizes.

Pairing heap

The practical choice in graph libraries and competitive-programming implementations that specifically need decrease-key β€” chosen over Fibonacci heap precisely because it is simpler to implement correctly and faster in measured practice, the trade Lecture 20 built the whole lecture around.

CSE3144 β€” Lecture 21 Β· Where each one runs
L21 Β· 09 β€” Recap & what's next ~2 min

Same contract, four different bets about when to pay

Lecture 22 β€” next

Introduction to Spatial Data Structures

CO CSE3144.4 β€” multidimensional data representation, setting up k-d Trees, Quad Trees, and R-Trees.

Homework β€” bring to Lecture 22
  • Build all four heaps by inserting 5, 40, 12, 35, 18 in that order (matching today's structure, different keys). Draw each final structure and count the structural operations for each.
  • In 3–4 sentences: why is Binary heap's UNION fundamentally O(n) while the other three can all do better β€” tie your answer to the array-vs-forest distinction from Axis 2.
  • Explain, in your own words, why Fibonacci heap's low operation count in today's animation was partly a matter of luck (which node happened to be decreased) rather than a guarantee β€” then describe a decrease-key call on today's final Fibonacci heap that WOULD trigger a cut.
CSE3144 β€” Lecture 21

Questions?

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

Next: Lecture 22 β€” Introduction to Spatial Data Structures.