Fibonacci Heaps

Outline for Today

● Recap from Last Time

● Quick refresher on binomial heaps and lazy binomial heaps. ● The Need for decrease-key

● An important operation in many graph algorithms. ● Fibonacci Heaps

● A efficiently supporting decrease- key. ● Representational Issues

● Some of the challenges in Fibonacci heaps.

Recap from Last Time

(Lazy) Binomial Heaps

● Last time, we covered the binomial and a variant called the lazy . ● These are structures designed to support efficient melding. ● Elements are stored in a collection of binomial trees.

2 1 2 0 7 4 5 5 1 3 8 7 6 9 8

Eager Binomial Heap

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1

2

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 2

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 3 2

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 3 2

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 3 2 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 3 2 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 2 3 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 3 2 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 3 2 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 3 2 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 3 2 6 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 3 2 6 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 3 2 6 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 7 3 2 6 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 7 3 2 6 8 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 7 3 2 6 8 4

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 3 2 6 4 7 8

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 3 2 7 6 4 8

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 3 2 7 6 4 8

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 2 3 7 6 4 8

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 5 2 3 7 6 4 8

Lazy Binomial Heap

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 9 5 2 3 7 6 4 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens if we enqueue the numbers

1, 2, 3, 4, 5, 6, 7, 8, and 9 into each heap. Eager Binomial Heap 1 9 5 2 3 7 6 4 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 1 9 5 2 3 7 6 4 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 9 5 2 3 7 6 4 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 9 5 2 3 7 6 4 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 5 3 9 7 6 4 2 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 5 3 9 7 6 4 2 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 5 3 9 7 6 4 2 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 5 3 2 7 6 4 9 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 5 3 7 6 4 8 2 9

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 5 3 7 6 4 8 2 9

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 5 2 7 6 3 9 8 4

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 5 2 7 6 3 9 8 4

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap

1 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap

2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 2 3 4 5 6 7 8 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 2 3 5 6 7 8 9 4

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 2 5 6 7 8 9 4

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 2 5 6 7 8 9 4

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 2 5 6 7 8 9 4

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 2 5 6 7 9 4 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 2 5 6 9 4 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 2 5 6 9 4 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 2 5 6 9 4 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 2 5 9 4 8 6

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 5 2 9 4 8 6

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 5 2 9 4 8 6

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 5 2 9 4 8 6

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 5 2 4 8 6 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 5 2 4 8 6 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 7 5 2 4 8 6 9

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 5 2 4 7 6 9 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 3 2 7 6 4 9 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 3 2 7 6 4 9 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 3 2 7 6 4 9 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 2 7 6 3 9 8 4

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 2 7 6 3 9 8 4

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 2 7 6 3 9 8 4

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 2 7 6 3 9 8 4

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap 2 5 9 3 7 6 4 8

Draw what happens after performing an

extract-min in each binomial heap. Eager Binomial Heap 2 5 9 3 7 6 4 8

Lazy Binomial Heap 2 5 9 3 7 6 4 8

Let’s enqueue 10, 11, and 12 into both heaps. Eager Binomial Heap 2 10 5 9 3 7 6 4 8

Lazy Binomial Heap 2 5 9 3 7 6 4 8

Let’s enqueue 10, 11, and 12 into both heaps. Eager Binomial Heap 2 10 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 5 9 3 7 6 4 8

Let’s enqueue 10, 11, and 12 into both heaps. Eager Binomial Heap 2 10 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 5 9 3 7 6 4 8

Let’s enqueue 10, 11, and 12 into both heaps. Eager Binomial Heap 2 10 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 5 9 3 7 6 4 8

Let’s enqueue 10, 11, and 12 into both heaps. Eager Binomial Heap 2 10 12 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 5 9 3 7 6 4 8

Let’s enqueue 10, 11, and 12 into both heaps. Eager Binomial Heap 2 10 12 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Let’s enqueue 10, 11, and 12 into both heaps. Eager Binomial Heap 2 10 12 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 2 10 12 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 10 12 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 10 12 5 9 3 11 7 6 4 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 5 10 12 7 6 11 9 8 3 4

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 5 10 12 7 6 11 9 8 3 4

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 5 10 12 7 6 11 9 8 3 4

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 5 10 9 7 6 11 12 8 3 4

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 5 10 9 7 6 11 12 8 3 4

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 5 10 9 7 6 11 12 8 3 4

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 5 9 10 4 7 6 12 11 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 5 9 10 4 7 6 12 11 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 5 9 10 4 7 6 12 11 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap 2 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap 10 11 12 5 9 3 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap 5 9 3 10 11 12 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 3 9 10 11 12 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 3 9 10 11 12 7 6 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 3 9 10 12 7 6 4 11 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 10 3 9 12 7 6 11 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 10 3 9 12 7 6 11 4 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 10 3 9 7 6 11 4 12 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 10 3 9 7 6 11 4 12 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 10 3 9 7 6 11 4 12 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 5 3 9 7 6 10 4 12 8 11

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 5 9 10 4 7 6 12 11 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 5 9 10 4 7 6 12 11 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 5 9 10 4 7 6 12 11 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap Order 2 Order 1 Order 0 3 9 5 4 10 12 7 6 11 8

Draw what happens after we do a

extract-min from both heaps. Eager Binomial Heap 3 9 5 4 10 12 7 6 11 8

Lazy Binomial Heap 3 9 5 4 10 12 7 6 11 8

Draw what happens after we do a

extract-min from both heaps. Operation Costs

● Eager Binomial Heap: ● Lazy Binomial Heap:

● enqueue: O(log n) ● enqueue: O(1) ● meld: O(log n) ● meld: O(1) ● find-min: O(log n) ● find-min: O(1) ● extract-min: O(log n) ● extract-min: O(log n)* (Nothing to see here.) ● *amortized

Intuition:Intuition: Each Each extract-min extract-min hashas to to do do a a bunch bunch of of cleanup cleanup forfor the the earlier earlier enqueue enqueue operations,operations, but but then then leaves leaves us us withwith few few trees. trees.

New Stuff!

The Need for decrease-key

The decrease-key Operation

● Some priority queues support the operation decrease-key(v, k), which works as follows: Given a pointer to an element v, lower its key (priority) to k. It is assumed that k is less than the current priority of v. ● This operation is crucial in efficient implementations of Dijkstra's algorithm and Prim's MST algorithm.

Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 5 1

start 4

10 1 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 ∞? ∞? 5 1

start 0? 4

10 1 ∞? ∞? 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 ∞? ∞? 5 1

start 0 4

10 1 ∞? ∞? 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 5? ∞? 5 1

start 0 4

10 1 10? ∞? 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 5 ∞? 5 1

start 0 4

10 1 10? ∞? 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 5 7? 5 1

start 0 4

10 1 10? 6? 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 5 7? 5 1

start 0 4

10 1 10? 6 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 5 7 5 1

start 0 4

10 1 10? 6 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 5 7 5 1

start 0 4

10 1 8? 6 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. 2 5 7 5 1

start 0 4

10 1 8 6 4 Dijkstra and decrease-key

● Dijkstra's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. ● Dijkstra's algorithm runtime is

O(n Tenq + n Text + m Tdec)

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 ∞? ∞? 1 10 ∞? ∞? 4 3 9 9

6 8 ∞? ∞? 5 2 ∞? ∞?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 ∞? 1? 1 10 10? ∞? 4 3 9 9

6 8 ∞? 5? 5 2 2? ∞?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 ∞? 1 10 10? ∞? 4 3 9 9

6 8 ∞? 5? 5 2 2? ∞?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 7? 1 10 10? ∞? 4 3 9 9

6 8 ∞? 5? 5 2 2? ∞?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 7? 1 10 10? ∞? 4 3 9 9

6 8 ∞? 5? 5 2 ∞?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 7? 1 10 9? ∞? 4 3 9 9

6 8 ∞? 5? 5 2 8?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 7? 1 10 9? ∞? 4 3 9 9

6 8 ∞? 5 2 8?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 4? 1 10 9? ∞? 4 3 9 9

6 8 6? 5 2 8?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 1 10 9? ∞? 4 3 9 9

6 8 6? 5 2 8?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 1 10 9? ∞? 4 3 9 9

6 8 3? 5 2 8?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 1 10 9? ∞? 4 3 9 9

6 8 5 2 8?

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 1 10 9? ∞? 4 3 9 9

6 5 2 8

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 1 10 9? 9? 4 3 9 9

6 5 2 8

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 1 10 9? 4 3 9 9

6 5 2 8

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 1 10 4? 4 3 9 9

6 5 2 8

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys.

7 4 1 10 4 3 9 9

6 5 2 8

Prim and decrease-key

● Prim's algorithm can be implemented with a priority queue using

● O(n) total enqueues,

● O(n) total extract-mins, and

● O(m) total decrease-keys. ● Prim's algorithm runtime is

O(n Tenq + n Text + m Tdec)

Standard Approaches

● In a , enqueue, extract-min, and decrease-key can be made to work in time O(log n) time each. ● Cost of Dijkstra's / Prim's algorithm:

= O(n Tenq + n Text + m Tdec) = O(n log n + n log n + m log n) = O(m log n)

Standard Approaches

● In a lazy binomial heap, enqueue takes amortized time O(1), and extract-min and decrease-key take amortized time O(log n). ● Cost of Dijkstra's / Prim's algorithm:

= O(n Tenq + n Text + m Tdec) = O(n + n log n + m log n) = O(m log n)

Where We're Going

● The has these amortized runtimes:

● enqueue: O(1)

● extract-min: O(log n).

● decrease-key: O(1). ● Cost of Prim's or Dijkstra's algorithm:

= O(n Tenq + n Text + m Tdec) = O(n + n log n + m) = O(m + n log n)

● This is theoretically optimal for a comparison-based priority queue in Dijkstra's or Prim's algorithms.

The Challenge of decrease-key

5 1 5 7 9 6 7 2 3 6 11 10 8 4 12

How might we implement decrease-key in a lazy binomial heap? 5 1 5 7 9 6 7 2 3 6 11 10 8 4 12

How might we implement decrease-key in a lazy binomial heap? 5 1 5 7 9 6 7 2 3 6 10 10 8 4 12

How might we implement decrease-key in a lazy binomial heap? 5 1 5 7 9 6 7 2 3 6 10 10 8 4 12

How might we implement decrease-key in a lazy binomial heap? 5 1 5 7 9 6 7 2 3 6 10 10 8 4 12

How might we implement decrease-key in a lazy binomial heap? 5 1 5 7 9 6 7 2 3 6 10 10 8 4 7

How might we implement decrease-key in a lazy binomial heap? 5 1 5 7 9 6 7 2 3 6 7 10 8 4 10

How might we implement decrease-key in a lazy binomial heap? 5 1 5 7 7 6 7 2 3 6 9 10 8 4 10

How might we implement decrease-key in a lazy binomial heap? IfIf our our lazy lazy binomialbinomial heap heap hashas n n nodes, nodes, how how talltall can can the the tallesttallest tree be? be? 5 1 5 7 7 6 7 2 3 6 9 10 8 4 SupposeSuppose the the biggest biggest k 10 tree has 2 knodes in it. tree has 2 nodes in it.

k Then 2 k≤ n. Then 2 ≤ n.

SoSo k k = = O(log O(log n n).).

How might we implement

decrease-key in a lazy binomial heap? IfIf our our lazy lazy binomialbinomial heap heap hashas n n nodes, nodes, how how talltall can can the the tallesttallest tree tree be? be? 5 1 5 7 7 6 7 2 3 6 9 10 8 4 SupposeSuppose the the biggest biggest k 10 tree has 2 knodes in it. tree has 2 nodes in it.

k Then 2 k≤ n. Then 2 ≤ n.

SoSo k k = = O(log O(log n n).).

Challenge: Support decrease-key

in (amortized) time O(1). 5 1 5 7 7 6 7 2 3 6 9 10 8 4 10

Challenge: Support decrease-key

in (amortized) time O(1). 5 1 5 7 7 6 7 2 3 6 9 10 8 4 10

Challenge: Support decrease-key

in (amortized) time O(1). 5 1 5 7 7 6 7 2 3 6 9 10 8 4 3

Challenge: Support decrease-key

in (amortized) time O(1). 5 1 5 7 7 6 7 2 3 6 9 10 8 4

WeWe cannot cannot have have all all three three of of these these 3 nice properties at once: nice properties at once:

1.1. decrease-key decrease-key takes takes time time O(1). O(1). 2.2. Our Our trees trees are are heap-ordered. heap-ordered. 3.3. Our Our trees trees are are binomial binomial trees. trees.

Challenge: Support decrease-key

in (amortized) time O(1). 5 1 5 7 7 6 7 2 3 6 9 10 8 4

WeWe cannot cannot have have all all three three of of these these 3 nice properties at once: nice properties at once:

1.1. decrease-key decrease-key takes takes time time O(1). O(1). 2.2. Our Our trees trees are are heap-ordered. heap-ordered. 3.3. Our Our trees trees are are binomial binomial trees. trees.

Challenge: Support decrease-key

in (amortized) time O(1). 5 1 5 7 7 6 7 2 3 6 9 10 8 4 3

Challenge: Support decrease-key

in (amortized) time O(1). 5 1 5 7 7 6 7 2 3 6 9 10 8 4 3

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 1 5 7 7 6 7 2 3 6 9 10 8 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 1 5 7 7 6 7 2 3 6 9 10 8 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 1 5 7 7 6 7 2 3 6 9 10 8 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 1 5 7 7 6 2 2 3 6 9 10 8 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 1 5 7 7 6 2 2 3 6 9 10 8 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 1 5 7 7 6 2 2 3 6 9 10 8 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 1 5 7 7 6 2 2 3 6 9 10 8 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 5 7 7 6 8 2 3 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 5 7 7 6 8 2 3 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 5 7 7 6 8 2 3 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 5 7 7 6 8 2 0 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 5 7 7 6 8 2 0 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 5 7 7 6 8 2 0 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 5 7 7 6 8 2 0 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 0 5 7 7 6 8 2 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 0 5 7 7 6 8 2 6 9 10 4

Challenge: Support decrease-key

in (amortized) time O(1). 3 5 2 1 0 5 7 7 6 8 2 6 9 10 4

Problem: What do we do in an extract-min? 3 5 2 1 0 5 7 7 6 8 2 6 9 10 4

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

5 9 3 10 11 12 7 6 4 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 9 10 11 12 7 6 4 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 9 10 11 12 7 6 4 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 9 10 11 7 6 4 12 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 11 9 10 7 6 4 12 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 11 9 10 7 6 4 12 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 11 9 10 7 6 4 12 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 11 9 7 6 4 12 10 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 9 11 7 6 4 10 12 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 9 11 7 6 4 10 12 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 9 11 7 6 4 10 12 8

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 11 7 6 9 4 12 8 10

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 11 7 6 9 4 12 8 10

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 5 3 11 7 6 9 4 12 8 10

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 3 11 5 9 4 12 7 6 10 8 What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 1 Order 0 3 11 5 9 4 12 7 6 10 8 What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

3 11 ThisThis system system assumes assumes we we can can assign an “order” to each tree. assign an “order” to each tree. That’s easy with binomial trees. 5 9 4 12 That’s easy with binomial trees. That’s harder with our new trees. That’s harder with our new trees.

7 6 10 WhatWhat should should we we do do here? here? 8 What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 0 Order 1 Order 0 Order 0 Order 0 5 9 3 10 11 12

7 6 4 Idea 1: A tree has order k Idea 1: Ak tree has order k if it has 2 knodes. if it has 2 nodes.

8 IdeaIdea 2: 2: A A tree tree has has order order k k ifif its its root root has has k k children. children.

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 0 Order 1 Order 0 Order 0 Order 0 5 9 3 10 11 12

7 6 4 Idea 1: A tree has order k Idea 1: Ak tree has order k if it has 2 knodes. if it has 2 nodes.

8 IdeaIdea 2: 2: A A tree tree has has order order k k ifif its its root root has has k k children. children.

What We Used to Do

Problem: What do we do in an extract-min? 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 0 Order 1 Order 0 Order 0 Order 0 5 9 3 10 11 12

7 6 4 Idea 1: A tree has order k Idea 1: Ak tree has order k if it has 2 knodes. if it has 2 nodes.

8 IdeaIdea 2: 2: A A tree tree has has order order k k ifif its its root root has has k k children. children.

What We Used to Do

Problem: What do we do in an extract-min? Order 0 Order 2 Order 1 Order 1 Order 1 Order 0 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Order 2 Order 0 Order 1 Order 0 Order 0 Order 0 5 9 3 10 11 12

7 6 4 Idea 1: A tree has order k Idea 1: Ak tree has order k if it has 2 knodes. if it has 2 nodes.

8 IdeaIdea 2: 2: A A tree tree has has order order k k ifif its its root root has has k k children. children.

What We Used to Do

Problem: What do we do in an extract-min? Order 0 Order 2 Order 1 Order 1 Order 1 Order 0 3 5 2 1 5 7 7 6 8 2 6 9 10 4 Idea 1: A tree has order k Idea 1: Ak tree has order k if it has 2 knodes. if it has 2 nodes.

IdeaIdea 2: 2: A A tree tree has has order order k k ifif its its root root has has k k children. children.

Problem: What do we do in an extract-min? Order 2 Order 1 Order 0 5 2 1 5 3 7 7 6 8 2 6 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 Order 0 5 2 1 5 3 7 7 6 8 2 6 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 Order 0 5 2 1 5 3 7 6 8 2 6 7 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 Order 0 5 2 1 5 3 7 6 8 2 6 7 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 Order 0 5 2 1 5 3 7 6 8 2 6 7 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 5 2 1 5 3 7 6 8 2 6 7 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 5 2 1 5 3 7 6 8 2 6 7 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 5 2 1 5 3 7 6 8 2 6 7 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 5 2 1 3 7 6 8 2 5 7 9 10 4 6

Problem: What do we do in an extract-min? Order 2 Order 1 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 3 5 2 1 5 7 7 6 8 2 6 9 10 4

Problem: What do we do in an extract-min? Order 2 Order 1 3 5 1 5 7 7 6 2 2 6 9 10 8 4

Problem: What do we do in an extract-min? Order 2 Order 1 1 3 5 2 2 5 7 7 6 8 4 6 9 10

Problem: What do we do in an extract-min? Order 2 1 3 5 2 2 5 7 7 6 8 4 6 9 10

Problem: What do we do in an extract-min? Order 3 Order 2 1 3 5 2 2 5 7 7 6 8 4 6 9 10

Problem: What do we do in an extract-min? Order 3 Order 2 1 3 5 2 2 5 7 7 6 8 4 6 9 10

Problem: What do we do in an extract-min? Order 3 Order 2 1 3 2 2 5 5 7 8 4 7 6 6 9 10

Problem: What do we do in an extract-min? Order 3 Order 2 3 1 5 5 7 2 2 7 6 6 8 4 9 10

Problem: What do we do in an extract-min? Order 3 Order 2 3 1 5 5 7 2 2 7 6 6 8 4 9 10

Problem: What do we do in an extract-min? 3 1 5 5 7 2 2 7 6 6 8 4 9 10

Problem: What do we do in an extract-min? 3 1 5 5 7 2 2 7 6 6 8 4 9 10

(1) To do a decrease-key, cut the node from its parent.

(2) Do extract-min as usual, using child count as order. Question:Question: How How efficientefficient is is this?this?

3 1 5 5 7 2 2 7 6 6 8 4 9 10

(1) To do a decrease-key, cut the node from its parent.

(2) Do extract-min as usual, using child count as order. FindFind a a series series of of operations operations that that givesgives rise rise to to a a heap heap containing containing a a singlesingle tree tree with with this this shape. shape.

Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. FindFind a a series series of of operations operations that that givesgives rise rise to to a a heap heap containing containing a a singlesingle tree tree with with this this shape. shape.

Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. Claim: Our trees can end up with very unusual shapes. k 1. enqueue 2 k+ 1 nodes. 1. enqueue 2 + 1 nodes. 2. Do an extract-min. 2. Do an extract-min.

3.3. UseUse decrease-key decrease-key and and extract-minextract-min to to prune prune the the tree. tree.

Claim: Our trees can end up with very unusual shapes. 1/2 Intuition: extract-min There are Θ(n 1/2) trees here. Intuition: extract-min There are Θ(n ) trees here. is only fast if it is only fast if it WhatWhat happens happens if if we we repeatedly repeatedly compacts nodes into a compacts nodes into a enqueueenqueue and and extract-min extract-min a a few trees. few trees. smallsmall value? value?

Claim: Because tree shapes aren’t well-constrained, we

can force extract-min to take amortized time Ω(n1/2). 1/2 Intuition: extract-min There are Θ(n 1/2) trees here. Intuition: extract-min There are Θ(n ) trees here. is only fast if it is only fast if it WhatWhat happens happens if if we we repeatedly repeatedly compacts nodes into a compacts nodes into a enqueueenqueue and and extract-min extract-min a a few trees. few trees. smallsmall value? value?

Claim: Because tree shapes aren’t well-constrained, we

can force extract-min to take amortized time Ω(n1/2). 1/2 Intuition: extract-min There are Θ(n 1/2) trees here. Intuition: extract-min There are Θ(n ) trees here. is only fast if it is only fast if it WhatWhat happens happens if if we we repeatedly repeatedly compacts nodes into a compacts nodes into a enqueueenqueue and and extract-min extract-min a a few trees. few trees. smallsmall value? value?

Claim: Because tree shapes aren’t well-constrained, we

can force extract-min to take amortized time Ω(n1/2). 1/2 Intuition: extract-min There are Θ(n 1/2) trees here. Intuition: extract-min There are Θ(n ) trees here. is only fast if it is only fast if it WhatWhat happens happens if if we we repeatedly repeatedly compacts nodes into a compacts nodes into a enqueueenqueue and and extract-min extract-min a a few trees. few trees. smallsmall value? value?

(Do a bunch of work to compact the trees, which doesn’t accomplish anything.)

Claim: Because tree shapes aren’t well-constrained, we

can force extract-min to take amortized time Ω(n1/2). 1/2 Intuition: extract-min There are Θ(n 1/2) trees here. Intuition: extract-min There are Θ(n ) trees here. is only fast if it is only fast if it WhatWhat happens happens if if we we repeatedly repeatedly compacts nodes into a compacts nodes into a enqueueenqueue and and extract-min extract-min a a few trees. few trees. smallsmall value? value?

Claim: Because tree shapes aren’t well-constrained, we

can force extract-min to take amortized time Ω(n1/2). 1/2 Intuition: extract-min There are Θ(n 1/2) trees here. Intuition: extract-min There are Θ(n ) trees here. is only fast if it is only fast if it WhatWhat happens happens if if we we repeatedly repeatedly compacts nodes into a compacts nodes into a enqueueenqueue and and extract-min extract-min a a few trees. few trees. smallsmall value? value?

Claim: Because tree shapes aren’t well-constrained, we

can force extract-min to take amortized time Ω(n1/2). 1/2 Intuition: extract-min There are Θ(n 1/2) trees here. Intuition: extract-min There are Θ(n ) trees here. is only fast if it is only fast if it WhatWhat happens happens if if we we repeatedly repeatedly compacts nodes into a compacts nodes into a enqueueenqueue and and extract-min extract-min a a few trees. few trees. smallsmall value? value?

(Do a bunch of work to compact the trees, which doesn’t accomplish anything.)

Claim: Because tree shapes aren’t well-constrained, we

can force extract-min to take amortized time Ω(n1/2). 1/2 Intuition: extract-min There are Θ(n 1/2) trees here. Intuition: extract-min There are Θ(n ) trees here. is only fast if it is only fast if it WhatWhat happens happens if if we we repeatedly repeatedly compacts nodes into a compacts nodes into a enqueueenqueue and and extract-min extract-min a a few trees. few trees. smallsmall value? value?

EachEach operation operation does does 1/2 Θ(Θ(nn1/2)) work, work, and and doesn’t doesn’t makemake any any future future operationsoperations any any better. better.

Claim: Because tree shapes aren’t well-constrained, we

can force extract-min to take amortized time Ω(n1/2). Order 3 Order 2 Order 1 Order 0

4 Nodes 3 Nodes 2 Nodes 1 Node

WithWith n n nodes, nodes, it’s it’s possible possible 1/2 toto have have Ω( Ω(nn1/2)) trees trees of of distinctdistinct orders. orders.

Question: Why didn’t this happen before? Order 3 Order 2 Order 1 Order 0

2 Nodes 1 Node

4 Nodes BinomialBinomial tree tree sizes sizes grow grow exponentially. exponentially. With n nodes, we can 8 Nodes With n nodes, we can havehave at at most most O(log O(log n n)) treestrees of of distinct distinct orders. orders.

Question: Why didn’t this happen before? Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Goal: Make tree sizes grow exponentially with order,

but still allow for subtrees to be cut out quickly. Intuition:Intuition: Allow Allow trees trees to to Rule:Rule: Nodes Nodes can can lose lose at at getget somewhat somewhat imbalanced, imbalanced, mostmost one one child. child. If If a a node node slowlyslowly propagating propagating losesloses two two children, children, cut cut it it informationinformation to to the the root. root. fromfrom its its parent. parent.

Question: Does this guarantee size? Maximally-Damaged Trees

● Here’s a binomial tree of order 4. That is, the root has four children. 4 ● Question: Using our marking scheme, how 0 1 2 3 many nodes can we remove without 0 1 0 0 1 2 changing the order of the tree? 0 0 1 0 ● Equivalently: how many nodes can we remove 0 without removing any Formulate a hypothesis, direct children of the Formulate a hypothesis, butbut don’t don’t post post anything anything root? inin chat chat just just yet yet. .  Maximally-Damaged Trees

● Here’s a binomial tree of order 4. That is, the root has four children. 4 ● Question: Using our marking scheme, how 0 1 2 3 many nodes can we remove without 0 1 0 0 1 2 changing the order of the tree? 0 0 1 0 ● Equivalently: how many nodes can we remove 0 without removing any Now, private chat me direct children of the Now, private chat me youryour best best guess guess. .Not Not root? sure?sure? Just Just answer answer “??”. “??”.   Maximally-Damaged Trees

Maximally-Damaged Trees

0

Maximally-Damaged Trees

0 1

0

Maximally-Damaged Trees

0 1

0 WeWe can't can't cut cut any any nodes nodes fromfrom this this tree tree without without makingmaking the the root root node node havehave order order 0. 0.

Maximally-Damaged Trees

0 1 2

0 1 0

0

Maximally-Damaged Trees

0 1 2 WeWe can't can't cut cut any any of of the the root'sroot's children children without without decreasingdecreasing its its order. order. 0 1 0

0

Maximally-Damaged Trees

0 1 2 WeWe can't can't cut cut any any of of the the root'sroot's children children without without decreasingdecreasing its its order. order. 0 1 0

0

However,However, we we can can cut cut this this node,node, leaving leaving the the root root nodenode with with two two children. children.

Maximally-Damaged Trees

0 1 2

0 0 0

Maximally-Damaged Trees

0 1 2 3

0 0 0 0 1 2

0 1 0

0

Maximally-Damaged Trees

0 1 2 3 AsAs before, before, we we can't can't cut cut any any ofof the the root's root's children children withoutwithout decreasing decreasing its its order. order. 0 0 0 0 1 2

0 1 0

0

Maximally-Damaged Trees

0 1 2 3 AsAs before, before, we we can't can't cut cut any any ofof the the root's root's children children withoutwithout decreasing decreasing its its order. order. 0 0 0 0 1 2

0 1 0

0 However,However, any any nodes nodes below below thethe second second layer layer are are fair fair gamegame to to be be eliminated. eliminated.

Maximally-Damaged Trees

0 1 2 3

0 0 0 0 1 2

0 1 0

0

Maximally-Damaged Trees

0 1 2 3

0 0 0 0 0 2

1 0

0

Maximally-Damaged Trees

0 1 2 3

0 0 0 0 0 1

0

Maximally-Damaged Trees

0 1 2 3

0 0 0 0 0 1

0

WeWe can't can't cut cut this this node node withoutwithout triggering triggering a a cascadingcascading cut, cut, so so we'rewe're done. done.

Maximally-Damaged Trees

0 1 2 3

0 0 0 0 0 1

0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 1 2 3

0 0 1 0 0 1 2

0 0 1 0

0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 1 2 3

0 0 1 0 0 1 2

0 0 1 0

0 WeWe can can start start chopping chopping away away atat these these nodes! nodes!

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 1 2 3

0 0 1 0 0 1 2

0 0 1 0

0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 0 2 3

0 1 0 0 1 2

0 0 1 0

0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 0 1 3

0 0 0 1 2

0 1 0

0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 0 1 2

0 0 0 1

0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 0 1 2

0 0 0 0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 0 1 2

0 0 0 0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 0 1 2

0 0 0 0

Maximally-Damaged Trees

0 1 2 3 4

0 0 0 0 0 1 0 0 1 2

0 0 0 0

Maximally-Damaged Trees

1 2 3 5 8 0 1 2 3 4

0 0 0 0 0 1 0 0 1 2

0 0 0 0

Maximally-Damaged Trees

1 2 3 5 8 0 1 2 3 4

0 0 0 0 0 1 0 0 1 2

0 0 0 0

Claim:Claim: TheThe minimumminimum numbernumber ofof nodesnodes inin aa

treetree ofof orderorder kk isis FₖFₖ₊₂₊₂ 1 2

TheseThese trees trees are are the the base base casescases for for our our inductive inductive lineline of of reasoning. reasoning.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! What’sWhat’s the the maximum maximum amount amount of of damagedamage we we can can do do to to this this tree tree A binomial tree without cutting any of the direct of order k+2. without cutting any of the direct childrenchildren of of the the root? root?

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A binomial tree of order k+2.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A binomial tree of order k+1. A binomial tree of order k+1.

We’reWe’re not not actually actually cutting cutting away away thisthis subtree. subtree. Instead, Instead, we’re we’re just just separatingseparating it it for for accounting accounting purposes.purposes. Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A binomial tree of order k+1.

RemoveRemove as as many many nodes nodes herehere as as possible possible without without cuttingcutting any any direct direct childrenchildren of of the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A (former) binomial tree of order k+1.

RemoveRemove as as many many nodes nodes herehere as as possible possible without without cuttingcutting any any direct direct childrenchildren of of the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A (former) binomial tree of order k+1.

RemoveRemove as as many many nodes nodes herehere as as possible possible without without cuttingcutting any any direct direct childrenchildren of of the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A (former) binomial tree of order k+1.

AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A binomial tree of order k+1.

AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1.

CutCut as as many many nodes nodes as as possiblepossible without without cuttingcutting more more than than two two childrenchildren from from the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A (former) binomial tree of order k+1.

AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1.

CutCut as as many many nodes nodes as as possiblepossible without without cuttingcutting more more than than two two childrenchildren from from the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A binomial tree of order k.

AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1.

CutCut as as many many nodes nodes as as possiblepossible without without cuttingcutting more more than than two two childrenchildren from from the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A binomial tree of order k.

AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1.

CutCut away away as as many many nodesnodes as as possible possible withoutwithout cutting cutting any any childrenchildren of of the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A (former) binomial tree of order k.

AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1.

CutCut away away as as many many nodesnodes as as possible possible withoutwithout cutting cutting any any childrenchildren of of the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A (former) binomial tree of order k.

AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1.

CutCut away away as as many many nodesnodes as as possible possible withoutwithout cutting cutting any any childrenchildren of of the the root. root.

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A (former) binomial tree of order k.

AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1. AA maximally- maximally- damageddamaged tree tree of of orderorder k k..

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! AA maximally- maximally- damageddamaged tree tree of of orderorder k k+1.+1. AA maximally- maximally- damageddamaged tree tree of of orderorder k k..

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! k Fact: Fk = Θ(φ ), where 1+ 5 φ = √ 2 is the golden ratio.

Corollary: The number of nodes in a tree of order k grows exponentially with k (approximately 1.61k versus our previous 2k).

Theorem: The minimum number of nodes in a tree of order k is Fₖ₊₂. Thanks to former CS166ers Kevin Tan and Max Arseneault for this proof approach! A Fibonacci heap is a lazy binomial heap with decrease-key implemented using the “lose at most one child” marking scheme.

How fast are the operations on Fibonacci heaps?

ΦΦ == tt

where where tt is is the the number number of of trees. trees.

ActualActual cost: cost: O(1) O(1) ΔΦ:ΔΦ: +1 +1

AmortizedAmortized cost: cost: O(1) O(1)..

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where tt is is the the number number of of trees. trees.

ThisThis is is the the same same analysis analysis from last lecture! from last lecture!

Cost:Cost: O( O(tt + + log log n n).). ΔΦ:ΔΦ: O(- O(-tt + + log log n n).). AmortizedAmortized cost: cost: O(log O(log nn))..

Each enqueue slowly introduces trees.

Each extract-min rapidly cleans them up. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Each decrease-key may trigger a chain of cuts.

Those chains happen due to previous decrease-keys. ΦΦ == tt

where where

tt is is the the number number of of trees. trees.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

ActualActual cost: cost: O(1) O(1) ΔΦ:ΔΦ: +2. +2.

AmortizedAmortized cost: cost: O(1) O(1)..

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

ActualActual cost: cost: O(1) O(1) ΔΦ:ΔΦ: +2. +2.

AmortizedAmortized cost: cost: O(1) O(1)..

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Actual cost: O(C) Suppose this Actual cost: O(C) Suppose this ΔΦ:ΔΦ: +1 +1 operationoperation did did C C total cuts. total cuts. AmortizedAmortized cost: cost: O( O(CC))..

Idea: Factor the number of marked nodes into our

potential to offset the cost of cascading cuts. ΦΦ == tt ++ mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

ActualActual cost: cost: O(1) O(1) ΔΦ:ΔΦ: +3. +3.

AmortizedAmortized cost: cost: O(1) O(1)..

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

ActualActual cost: cost: O(1) O(1) ΔΦ:ΔΦ: +3. +3.

AmortizedAmortized cost: cost: O(1) O(1)..

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. ΦΦ == tt ++ 22mm

where where

tt is is the the number number of of trees trees and and mm is is the the number number of of marked marked nodes. nodes.

ActualActual cost: cost: O( O(CC)) ΔΦ:ΔΦ: - C-C + + 1 1

AmortizedAmortized cost: cost: O( O(11))..

Idea 2: Each decrease-key hurts twice: once in a

cascading cut, and once in an extract-min. The Overall Analysis

● Here’s the final scorecard for the enqueue: O(1) Fibonacci heap. ● These are excellent find-min: O(1) theoretical runtimes. There’s minimal room meld: O(1) for improvement! extract-min: O(log n)* ● Later work made all these operations decrease-key: O(1)* worst-case efficient at a significant increase in both runtime and * intellectual amortized complexity.

Representation Issues

Representing Trees

● The trees in a Fibonacci heap must be able to do the following:

● During a merge: Add one tree as a child of the root of another tree. ● During a cut: Cut a node from its parent in time O(1). ● Claim: This is trickier than it looks.

Representing Trees

A

B C D E

Representing Trees

A A

B C D E B C D E

Representing Trees

A A

B C D E B C D E

Representing Trees

A A D

B C E B C D E

Representing Trees

A A D

B C E B C D E

Representing Trees

A A D

B C E B C D E

Representing Trees

A A D

B C E B C D E

FindingFinding this this pointerpointer might might take take time Θ(log n)! time Θ(log n)! The Solution

The Solution

ThisThis is is going going to to be be weird. weird.

Sorry.Sorry.

The Solution

A

B C D E

The Solution

A TheThe parent parent EachEach node node stores stores a a stores a pointer pointer to its parent. stores a pointer pointer to its parent. toto an an arbitrary arbitrary child.child.

B C D E

TheThe children children of of each each nodenode are are in in a a circularly, circularly, doubly-linkeddoubly-. list. The Solution

A

B C D E

The Solution

A

B C D E

The Solution

A

B C E

The Solution

A

B C E

ToTo cut cut a a node node from from its its parent, parent, if if it it isn'tisn't the the representative representative child, child, just just

splicesplice it it out out of of its its linked linked list. list. The Solution

A

B C E

The Solution

A

B C E

The Solution

A

B C E

The Solution

A

B C

The Solution

A

B C

IfIf it it is is the the representative, representative, change change thethe parent's parent's representative representative child child to to

bebe one one of of the the node's node's siblings. siblings. Awful Linked Lists

● Trees are stored as follows:

● Each node stores a pointer to some child. ● Each node stores a pointer to its parent. ● Each node is in a circularly-linked list of its siblings. ● The following possible are now possible in time O(1):

● Cut a node from its parent. ● Add another child node to a node.

Fibonacci Heap Nodes

● Each node in a Fibonacci heap stores

● A pointer to its parent. ● A pointer to the next sibling. ● A pointer to the previous sibling. ● A pointer to an arbitrary child. ● A bit for whether it's marked. ● Its order. ● Its key. ● Its element.

In Practice

● In practice, the constant factors on Fibonacci heaps make it slower than other heaps, except on huge graphs or workflows with tons of decrease-keys. ● Why?

● Huge memory requirements per node. ● High constant factors on all operations. ● Poor locality of reference and caching.

In Theory

● That said, Fibonacci heaps are worth knowing about for several reasons:

● Clever use of a two-tiered potential function shows up in lots of data structures. ● Implementation of decrease-key forms the basis for many other advanced priority queues. ● Gives the theoretically optimal comparison- based implementation of Prim's and Dijkstra's algorithms.

More to Explore

● Since the development of Fibonacci heaps, there have been a number of other priority queues with similar runtimes.

● In 1986, a powerhouse team (Fredman, Sedgewick, Sleator, and Tarjan) invented the . It’s much simpler than a Fibonacci heap, is fast in practice, but its runtime bounds are unknown! ● In 2012, Brodal et al. invented the strict Fibonacci heap. It has the same time bounds as a Fibonacci heap, but in a worst-case rather than amortized sense. ● In 2013, Chan invented the quake heap. It matches the asymptotic bounds of a Fibonacci heap but uses a totally different strategy. ● Also interesting to explore: if the weights on the edges in a graph are chosen from a continuous distribution, the expected number of decrease-keys in Dijkstra’s algorithm is O(n log (m / n)). That might counsel another heap structure! ● Also interesting to explore: binary heaps generalize to b-ary heaps, where each node has b children. Picking b = log (2 + ᵐ/ₙ) makes Dijkstra and Prim run in time O(m log n / log ᵐ/ₙ), which is O(m) if m = Θ(n1+ε) for any ε > 0. Next Time

● Randomized Data Structures

● Doing well on average, broadly speaking. ● Frequency Estimation

● Counting in sublinear space. ● Count-Min Sketches

● A simple, elegant, fast, and widely-used data structure.