X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank...

177
5.2 Fibonacci Heaps Frank Stajano Thomas Sauerwald Lent 2015 58 30 10 43 41 41 33 70 70 32 54 66 82 51 min

Transcript of X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank...

Page 1: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

5.2 Fibonacci HeapsFrank Stajano Thomas Sauerwald

Lent 2015

Use of Amortized Analysis

PUSH(T)

T

PUSH(B)

T

B

PUSH(X)

T

B

X

POP

T

B

PUSH(D)

T

B

D

MULTIPOP(3)

58 30 10

43 4141 33 7070 32

54 66 82 51

min

5

0

s4

5

5

9

11

3

1

51

3 1

2

3

0

41

2

1

3

Amortized Analysis

Fibonacci Heaps

Finding Shortest Paths

next week

⇡ two weeks

5.1: Amortized Analysis T.S. 2

Page 2: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Priority Queues Overview

Operation Linked list Binary heap Binomial heap

Fibon. heap

MAKE-HEAP O(1) O(1) O(1)

O(1)

INSERT O(1) O(log n) O(log n)

O(1)

MINIMUM O(n) O(1) O(log n)

O(1)

EXTRACT-MIN O(n) O(log n) O(log n)

O(log n)

MERGE O(n) O(n) O(log n)

O(1)

DECREASE-KEY O(1) O(log n) O(log n)

O(1)

DELETE O(1) O(log n) O(log n)

O(log n)

5.2: Fibonacci Heaps T.S. 2

Page 3: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Priority Queues Overview

Operation Linked list Binary heap Binomial heap Fibon. heap

MAKE-HEAP O(1) O(1) O(1) O(1)INSERT O(1) O(log n) O(log n) O(1)

MINIMUM O(n) O(1) O(log n) O(1)EXTRACT-MIN O(n) O(log n) O(log n) O(log n)

MERGE O(n) O(n) O(log n) O(1)DECREASE-KEY O(1) O(log n) O(log n) O(1)

DELETE O(1) O(log n) O(log n) O(log n)

5.2: Fibonacci Heaps T.S. 2

Page 4: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

5.2: Fibonacci Heaps T.S. 3

Page 5: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

5.2: Fibonacci Heaps T.S. 3

Page 6: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

5.2: Fibonacci Heaps T.S. 3

Page 7: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

Binomial Heap: k/2 DECREASE-KEY+ k/2 INSERT

c1 = c2 = · · · = ck = O(log n)

⇒ ∑ki=1 ci = O(k log n)

5.2: Fibonacci Heaps T.S. 3

Page 8: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

Binomial Heap: k/2 DECREASE-KEY+ k/2 INSERT

c1 = c2 = · · · = ck = O(log n)

⇒ ∑ki=1 ci = O(k log n)

5.2: Fibonacci Heaps T.S. 3

Page 9: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

Binomial Heap: k/2 DECREASE-KEY+ k/2 INSERT

c1 = c2 = · · · = ck = O(log n)

⇒ ∑ki=1 ci = O(k log n)

5.2: Fibonacci Heaps T.S. 3

Page 10: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

Binomial Heap: k/2 DECREASE-KEY+ k/2 INSERT

c1 = c2 = · · · = ck = O(log n)

⇒ ∑ki=1 ci = O(k log n)

Fibonacci Heap: k/2DECREASE-KEY + k/2 INSERT

c̃1 = c̃2 = · · · = c̃k = O(1)⇒ ∑k

i=1 ci ≤∑k

i=1 c̃i = O(k)

5.2: Fibonacci Heaps T.S. 3

Page 11: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

Binomial Heap: k/2 DECREASE-KEY+ k/2 INSERT

c1 = c2 = · · · = ck = O(log n)

⇒ ∑ki=1 ci = O(k log n)

Fibonacci Heap: k/2DECREASE-KEY + k/2 INSERT

c̃1 = c̃2 = · · · = c̃k = O(1)

⇒ ∑ki=1 ci ≤

∑ki=1 c̃i = O(k)

5.2: Fibonacci Heaps T.S. 3

Page 12: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

actual cost amortized cost

MAKE-HEAP O(1) O(1)INSERT O(log n) O(1)

MINIMUM O(log n) O(1)EXTRACT-MIN O(log n) O(log n)

MERGE O(log n) O(1)DECREASE-KEY O(log n) O(1)

DELETE O(log n) O(log n)

All these cost bounds holdif n is the size of the heap.

Binomial Heap: k/2 DECREASE-KEY+ k/2 INSERT

c1 = c2 = · · · = ck = O(log n)

⇒ ∑ki=1 ci = O(k log n)

Fibonacci Heap: k/2DECREASE-KEY + k/2 INSERT

c̃1 = c̃2 = · · · = c̃k = O(1)⇒ ∑k

i=1 ci ≤∑k

i=1 c̃i = O(k)5.2: Fibonacci Heaps T.S. 3

Page 13: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Actual vs. Amortized Cost

k0

O(1)2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 c̃i

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 14: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Actual vs. Amortized Cost

k0

O(1)2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 c̃i

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 15: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Actual vs. Amortized Cost

k0

O(1)2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 c̃i

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 16: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Actual vs. Amortized Cost

k0

O(1)2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 c̃i

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 17: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Actual vs. Amortized Cost

k0

O(1)2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 c̃i

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 18: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Outline

Structure

Operations

Glimpse at the Analysis

5.2: Fibonacci Heaps T.S. 5

Page 19: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Reminder: Binomial Heaps

Binomial Trees

B(0) B(1) B(2) B(3) B(k)

B(k − 1)

B(k − 1)

Binomial Heap is a collection of binomial trees of different orders,each of which obeys the heap property

Operations:

MERGE: Merge two binomial heaps using Binary Addition ProcedureINSERT: Add B(0) and perform a MERGEEXTRACT-MIN: Find tree with minimum key, cut it and perform a MERGEDECREASE-KEY: The same as in a binary heap

Binomial Heaps

5.2: Fibonacci Heaps T.S. 6

Page 20: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Reminder: Binomial Heaps

Binomial Trees

B(0) B(1) B(2) B(3) B(k)

B(k − 1)

B(k − 1)

Binomial Heap is a collection of binomial trees of different orders,each of which obeys the heap propertyOperations:

MERGE: Merge two binomial heaps using Binary Addition ProcedureINSERT: Add B(0) and perform a MERGEEXTRACT-MIN: Find tree with minimum key, cut it and perform a MERGEDECREASE-KEY: The same as in a binary heap

Binomial Heaps

5.2: Fibonacci Heaps T.S. 6

Page 21: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Reminder: Binomial Heaps

Binomial Trees

B(0) B(1) B(2) B(3) B(k)

B(k − 1)

B(k − 1)

Binomial Heap is a collection of binomial trees of different orders,each of which obeys the heap propertyOperations:

MERGE: Merge two binomial heaps using Binary Addition ProcedureINSERT: Add B(0) and perform a MERGEEXTRACT-MIN: Find tree with minimum key, cut it and perform a MERGEDECREASE-KEY: The same as in a binary heap

Binomial Heaps

5.2: Fibonacci Heaps T.S. 6

Page 22: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 23: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 24: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 25: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 26: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 27: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 28: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 29: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 30: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 31: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 32: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 33: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 34: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 35: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 36: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 37: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Merging two Binomial Heaps

3

6 8

10

5

7

15

+

1

4 9 11

12 17 13

16

14

18

2

2

15

5

7 14

18

3

6 8

10

5

7 14

18

1

4 9 11

12 17 13

16

3

6 8

10

5

7 14

18

0 0 1 1 1 = 70 1 0 1 1 = 111 1 1 1

1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7

Page 38: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Structure

Binomial Heap:consists of binomial trees, and every order appears at most onceimmediately tidy up after INSERT or MERGE

5

38 51

63

7

50 26 22

37 30 48

54

Fibonacci Heap:forest of MIN-HEAPslazily defer tidying up; do it on-the-fly when search for the MIN

37 22 5

50 38 26 19 7

66 48

30

51

5.2: Fibonacci Heaps T.S. 8

Page 39: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Binomial Heap vs. Fibonacci Heap: Structure

Binomial Heap:consists of binomial trees, and every order appears at most onceimmediately tidy up after INSERT or MERGE

5

38 51

63

7

50 26 22

37 30 48

54

Fibonacci Heap:forest of MIN-HEAPslazily defer tidying up; do it on-the-fly when search for the MIN

37 22 5

50 38 26 19 7

66 48

30

51

5.2: Fibonacci Heaps T.S. 8

Page 40: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43 41

41

33 70

70

32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 41: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43 41

41

33 70

70

32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 42: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43 41

41

33 70

70

32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 43: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43

41

41 33

70

70 32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 44: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43

41

41 33

70

70 32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 45: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43

41

41 33

70

70 32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 46: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43

41

41 33

70

70 32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 47: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43

41

41 33

70

70 32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 48: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Structure of Fibonacci Heaps

Forest of MIN-HEAPs

Nodes can be marked (roots are always unmarked)

Tree roots are stored in a circular, doubly-linked list

Min-Pointer pointing to the smallest element

Fibonacci Heap

58 30 10

43

41

41 33

70

70 32

54 66 82 51

min

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9

Page 49: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

A single Node

payload

0

marked

3

degreeb f

p

c

Previous Sibling Next Sibling

Parent

One of the Children

5.2: Fibonacci Heaps T.S. 10

Page 50: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Magnifying a Four-Node Portion

30 0 3

43 0 0 41 1 2 33 0 1

1058

54 82

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 11

Page 51: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Magnifying a Four-Node Portion

30 0 3

43 0 0 41 1 2 33 0 1

1058

54 82

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 11

Page 52: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Magnifying a Four-Node Portion

30 0 3

43 0 0 41 1 2 33 0 1

1058

54 82

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 11

Page 53: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Outline

Structure

Operations

Glimpse at the Analysis

5.2: Fibonacci Heaps T.S. 12

Page 54: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: INSERT

Create a singleton tree

Add to root list

and update min-pointer (if necessary)

INSERT

17 24 23 7 3

30 26 46

35

18 52 41

39 44

min

21

21

21

Actual Costs: O(1)

5.2: Fibonacci Heaps T.S. 13

Page 55: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: INSERT

Create a singleton tree

Add to root list

and update min-pointer (if necessary)

INSERT

17 24 23 7 3

30 26 46

35

18 52 41

39 44

min

21

21

21

Actual Costs: O(1)

5.2: Fibonacci Heaps T.S. 13

Page 56: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: INSERT

Create a singleton tree

Add to root list

and update min-pointer (if necessary)

INSERT

17 24 23 7 3

30 26 46

35

18 52 41

39 44

min

21

21

21

Actual Costs: O(1)

5.2: Fibonacci Heaps T.S. 13

Page 57: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: INSERT

Create a singleton tree

Add to root list

and update min-pointer (if necessary)

INSERT

17 24 23 7 3

30 26 46

35

18 52 41

39 44

min

21

21

21

Actual Costs: O(1)

5.2: Fibonacci Heaps T.S. 13

Page 58: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: INSERT

Create a singleton tree

Add to root list and update min-pointer (if necessary)

INSERT

17 24 23 7 3

30 26 46

35

18 52 41

39 44

min

21

21

21

Actual Costs: O(1)

5.2: Fibonacci Heaps T.S. 13

Page 59: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: INSERT

Create a singleton tree

Add to root list and update min-pointer (if necessary)

INSERT

17 24 23 7 3

30 26 46

35

18 52 41

39 44

min

21

21

21

Actual Costs: O(1)

5.2: Fibonacci Heaps T.S. 13

Page 60: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min

X

Meld childen into root list and unmark them

X

Consolidate so that no roots have the same degree

(# children) X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 61: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min

X

Meld childen into root list and unmark them

X

Consolidate so that no roots have the same degree

(# children) X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 62: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them

X

Consolidate so that no roots have the same degree

(# children) X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 63: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them

X

Consolidate so that no roots have the same degree

(# children) X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 64: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them

X

Consolidate so that no roots have the same degree

(# children) X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 65: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them

X

Consolidate so that no roots have the same degree

(# children) X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 66: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree

(# children) X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 67: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree

(# children) X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 68: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 69: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2

degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 70: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 71: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2

degree=0

1 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 72: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 73: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=0

1 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 74: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 75: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 76: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 77: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 78: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 79: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 80: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 81: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 82: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7 23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

2317

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 83: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 84: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 85: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 86: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 87: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 88: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 89: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 90: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 91: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 92: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 93: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 94: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 95: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 96: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 97: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52 41

4439

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 98: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 99: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 100: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children)

X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 101: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children) X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 102: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children) X

Update minimum

X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 103: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children) X

Update minimum X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

min

Actual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 104: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children) X

Update minimum X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 105: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children) X

Update minimum X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs:

O(trees(H) + d(n))

Every root becomes child of another root at most once!

d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 106: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: EXTRACT-MIN

Delete min X

Meld childen into root list and unmark them X

Consolidate so that no roots have the same degree (# children) X

Update minimum X

EXTRACT-MIN

7

23 17

30

24

26 46

35

3

18 52 41

39 44

min

18 52

41

44

39

degree=2 degree=01 2 0 0 1 0 1

degree0 1 2 3

17

23

17

23

24

26 46

35

41

44

minActual Costs: O(trees(H) + d(n))

Every root becomes child of another root at most once!

d(n) is the maximum degree of aroot in any Fibonacci heap of size n

5.2: Fibonacci Heaps T.S. 14

Page 107: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)

Check if heap-order is violated

If not

, then done.

Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24 17 23

26 46 30

35

18

21

52

39

38

41

2020

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 108: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)

Check if heap-order is violated

If not

, then done.

Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24 17 23

26 46 30

35

18

21

52

39

38

41

2020

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 109: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)

Check if heap-order is violated

If not

, then done.

Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24 17 23

26 46 30

35

18

21

52

39

38

4120

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 110: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not

, then done.

Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 111: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not

, then done.

Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 112: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not

, then done.Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 113: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.

Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 114: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 115: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 116: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 117: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 118: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise,

cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 119: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 120: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 121: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 122: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 123: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 124: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 125: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 126: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 127: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 128: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26

46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 129: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 130: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 131: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 132: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 133: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 134: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 135: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 136: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 137: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 138: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 139: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 140: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 141: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 142: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY (First Attempt)

Decrease the key of x (given by a pointer)Check if heap-order is violated

If not, then done.Otherwise, cut tree rooted at x and meld into root list (update min).

DECREASE-KEY of node x

7

24

17 23

26 46 30

35

18

21

52

39

38

41

20

20

15

15

15

5

5

min

5

min

19

19

19

12

12

12

Wide andshallow tree

Degree = 3,Nodes = 4

Peculiar Constraint: Make sure that each non-rootnode loses at most one child before becoming root

5.2: Fibonacci Heaps T.S. 15

Page 143: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list

and:

Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26 46 30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 144: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list

and:

Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26 46 30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 145: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list

and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26 46 30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 146: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list

and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 147: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list

and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 148: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list

and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 149: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:

Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 150: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 151: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 152: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 153: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 154: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 155: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 156: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 157: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 158: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 159: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)

If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5

26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 160: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked,

unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5

26 247

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 161: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5

26 247

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 162: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26

247

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 163: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26

247

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 164: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26

247

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 165: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 24

7

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 166: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24 17 23

26

46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 24

7

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 167: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 168: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16

Page 169: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16

Page 170: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Fibonacci Heap: DECREASE-KEY

Decrease the key of x (given by a pointer)

(Here we consider only cases where heap-order is violated)

⇒ Cut tree rooted at x , unmark x , meld into root list and:Check if parent node is marked

If unmarked, mark it (unless it is a root)If marked, unmark and meld it into root list and recurse (Cascading Cut)

DECREASE-KEY of node x

7

24

17 23

26 46

30

35

18

21

52

39

38

41

15

15

15

24

5

5

5 26 247

min

minActual Cost: O(# cuts)

1. DECREASE-KEY 46 15 X

2. DECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16

Page 171: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Outline

Structure

Operations

Glimpse at the Analysis

5.2: Fibonacci Heaps T.S. 17

Page 172: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1)

EXTRACT-MIN: actual O(trees(H) + d(n))

amortized O(d(n))

DECREASE-KEY: actual O(# cuts) ≤ O(marks(H))

amortized O(1)

Φ(H) = trees(H)+2·marks(H)

7

24 17 23

26 46 30

35

18

21

52

39

38

41

Lifecycle of a node

26

26

26

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps T.S. 18

Page 173: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1)

EXTRACT-MIN: actual O(trees(H) + d(n))

amortized O(d(n))

DECREASE-KEY: actual O(# cuts) ≤ O(marks(H))

amortized O(1)

Φ(H) = trees(H)+2·marks(H)

7

24 17 23

26 46 30

35

18

21

52

39

38

41

Lifecycle of a node

26

26

26

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps T.S. 18

Page 174: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1)

EXTRACT-MIN: actual O(trees(H) + d(n))

amortized O(d(n))

DECREASE-KEY: actual O(# cuts) ≤ O(marks(H))

amortized O(1)

Φ(H) = trees(H)+2·marks(H)

7

24 17 23

26 46 30

35

18

21

52

39

38

41

Lifecycle of a node

26

26

26

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps T.S. 18

Page 175: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1)

EXTRACT-MIN: actual O(trees(H) + d(n))

amortized O(d(n))

DECREASE-KEY: actual O(# cuts) ≤ O(marks(H))

amortized O(1)

Φ(H) = trees(H)+2·marks(H)

7

24 17 23

26 46 30

35

18

21

52

39

38

41

Lifecycle of a node

26

26

26

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps T.S. 18

Page 176: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1)

EXTRACT-MIN: actual O(trees(H) + d(n))

amortized O(d(n))

DECREASE-KEY: actual O(# cuts) ≤ O(marks(H))

amortized O(1)

Φ(H) = trees(H)+2·marks(H)

7

24 17 23

26 46 30

35

18

21

52

39

38

41

Lifecycle of a node

26

26

26

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps T.S. 18

Page 177: X D Use of Amortized Analysis B T PUSH(T) PUSH(B) PUSH(X ... · 5.2 Fibonacci Heaps Frank StajanoThomas Sauerwald Lent 2015 Use of Amortized Analysis PUSH(T) T PUSH(B) T B PUSH(X)

Amortized Analysis via Potential Method

INSERT: actual O(1) amortized O(1)EXTRACT-MIN: actual O(trees(H) + d(n)) amortized O(d(n))DECREASE-KEY: actual O(# cuts) ≤ O(marks(H)) amortized O(1)

Φ(H) = trees(H)+2·marks(H)

7

24 17 23

26 46 30

35

18

21

52

39

38

41

Lifecycle of a node

26

26

26Lo

ses

seco

ndch

ild Consolidate

Loses first child

5.2: Fibonacci Heaps T.S. 18