5.2 fibonacci heapsbinomial heaps 5.2: fibonacci heaps t.s. 6. reminder: binomial heaps binomial...

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

Upload: others

Post on 09-Jul-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

5.2 Fibonacci HeapsFrank Stajano Thomas Sauerwald

Lent 2016

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 2: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

5.2: Fibonacci Heaps T.S. 3

Page 5: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

5.2: Fibonacci Heaps T.S. 3

Page 6: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

5.2: Fibonacci Heaps T.S. 3

Page 7: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

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

c1 = c2 = · · · = ck = O(1)

⇒ ∑ki=1 ci ≤

∑ki=1 ci = O(k)

5.2: Fibonacci Heaps T.S. 3

Page 11: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

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

c1 = c2 = · · · = ck = O(1)

⇒ ∑ki=1 ci ≤

∑ki=1 ci = O(k)

5.2: Fibonacci Heaps T.S. 3

Page 12: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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)

n is the number of items in the heap when the operation is performed.

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

c1 = c2 = · · · = ck = O(1)

⇒ ∑ki=1 ci ≤

∑ki=1 ci = O(k)

5.2: Fibonacci Heaps T.S. 3

Page 13: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Actual vs. Amortized Cost

k0

O(1)

2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 ci

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 14: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Actual vs. Amortized Cost

k0

O(1)

2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 ci

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 15: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Actual vs. Amortized Cost

k0

O(1)

2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 ci

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 16: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Actual vs. Amortized Cost

k0

O(1)

2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 ci

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 17: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Actual vs. Amortized Cost

k0

O(1)

2 · O(1)

14 · O(1)

1 2 14

Potential

∑ki=1 ci

∑ki=1 ci

Potential ≥ 0, but should bealso as small as possible

5.2: Fibonacci Heaps T.S. 4

Page 18: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Outline

Structure

Operations

Glimpse at the Analysis

Amortized Analysis

5.2: Fibonacci Heaps T.S. 5

Page 19: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Outline

Structure

Operations

Glimpse at the Analysis

Amortized Analysis

5.2: Fibonacci Heaps T.S. 12

Page 54: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min

XMeld 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them

XConsolidate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them

XConsolidate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them

XConsolidate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree

(# children) XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children)

XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children) XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children) XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children) XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children) XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: EXTRACT-MIN

Delete min XMeld childen into root list and unmark them XConsolidate so that no roots have the same degree (# children) XUpdate 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 ofanother 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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

2020

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 108: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

2020

15

15

15

99

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

1. DECREASE-KEY 24 20

2. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 109: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

4120

20

15

15

15

99

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

1. DECREASE-KEY 24 20

2. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 110: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 20

2. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 111: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 20

2. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 112: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 20

2. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 113: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 20

2. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 114: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 20

2. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 115: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 15

3. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 116: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 15

3. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 117: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 15

3. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 118: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 15

3. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 119: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 15

3. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 120: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

99

35

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 15

3. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 121: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

99

35

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 5

4. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 122: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

99

35

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 5

4. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 123: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 5

4. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 124: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 5

4. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 125: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 5

4. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 126: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 5

4. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 127: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 19

5. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 128: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 19

5. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 129: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 19

5. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 130: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 19

5. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 131: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 19

5. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 132: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 19

5. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 133: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 134: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 135: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 136: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 137: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 138: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 139: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 140: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 141: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 142: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Fibonacci Heap: DECREASE-KEY (First Try)

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

9935

18

21

52

39

38

41

20

20

15

15

15

99

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

1. DECREASE-KEY 24 202. DECREASE-KEY 46 153. DECREASE-KEY 35 54. DECREASE-KEY 26 195. DECREASE-KEY 30 12

5.2: Fibonacci Heaps T.S. 15

Page 143: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 145: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 146: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 147: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 148: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 149: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

99

24

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 150: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

99

24

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 151: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

99

24

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 152: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15

X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 153: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

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: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 155: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 156: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 157: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

99

35

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 158: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 159: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5

26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 160: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5

26 24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 161: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5

26 24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 162: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26

24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 163: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26

24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 164: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26

24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 165: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 166: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

9924

5

5

5 26 24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 167: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

99

24

5

5

5 26 24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5

X

5.2: Fibonacci Heaps T.S. 16

Page 168: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

99

24

5

5

5 26 24

min

min

Actual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16

Page 169: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

99

24

5

5

5 26 24

min

minActual Cost:

O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16

Page 170: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

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

9935

18

21

52

39

38

41

15

15

15

99

24

5

5

5 26 24

min

minActual Cost: O(# cuts)

1. DECREASE-KEY 46 15 X2. DECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16

Page 171: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

5.2 Fibonacci Heaps (Analysis)Frank Stajano Thomas Sauerwald

Lent 2016

Amortized Analysis via Potential Method

INSERT: actual O(1) amortized O(1) XEXTRACT-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

18

18

18

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps (Analysis) T.S. 3

Page 172: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Outline

Structure

Operations

Glimpse at the Analysis

Amortized Analysis

5.2: Fibonacci Heaps (Analysis) T.S. 2

Page 173: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1) X

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

18

18

18

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps (Analysis) T.S. 3

Page 174: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1) X

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

18

18

18

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps (Analysis) T.S. 3

Page 175: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1) X

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

18

18

18

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps (Analysis) T.S. 3

Page 176: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1) X

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

18

18

18

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps (Analysis) T.S. 3

Page 177: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis via Potential Method

INSERT: actual O(1)

amortized O(1) X

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

18

18

18

Lose

sse

cond

child C

onsolidate

Loses first child

5.2: Fibonacci Heaps (Analysis) T.S. 3

Page 178: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis via Potential Method

INSERT: actual O(1) amortized O(1)

X

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

18

18

18Lo

ses

seco

ndch

ild Consolidate

Loses first child

5.2: Fibonacci Heaps (Analysis) T.S. 3

Page 179: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis via Potential Method

INSERT: actual O(1) amortized O(1) XEXTRACT-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

18

18

18Lo

ses

seco

ndch

ild Consolidate

Loses first child

5.2: Fibonacci Heaps (Analysis) T.S. 3

Page 180: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Outline

Structure

Operations

Glimpse at the Analysis

Amortized Analysis

5.2: Fibonacci Heaps (Analysis) T.S. 4

Page 181: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) =

trees(H) + x

marks(H ′) ≤

marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 182: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) =

trees(H) + x

marks(H ′) ≤

marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 183: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) =

trees(H) + x

marks(H ′) ≤

marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 184: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) =

trees(H) + x

marks(H ′) ≤

marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 185: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) = trees(H) + x

marks(H ′) ≤

marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 186: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) = trees(H) + x

marks(H ′) ≤

marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 187: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) = trees(H) + x

marks(H ′) ≤ marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 188: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) = trees(H) + x

marks(H ′) ≤ marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 189: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) = trees(H) + x

marks(H ′) ≤ marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ

≤ O(x + 1) + 4− x = O(1)

Amortized Cost

Scale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 190: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) = trees(H) + x

marks(H ′) ≤ marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ ≤ O(x + 1) + 4− x

= O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 191: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) = trees(H) + x

marks(H ′) ≤ marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ ≤ O(x + 1) + 4− x = O(1)

Amortized CostScale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5

Page 192: 5.2 Fibonacci HeapsBinomial Heaps 5.2: Fibonacci Heaps T.S. 6. 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

Amortized Analysis of DECREASE-KEY

DECREASE-KEY: O(x + 1), where x is the number of cuts.

Actual Cost

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

trees(H ′) = trees(H) + x

marks(H ′) ≤ marks(H)− x + 2

⇒ ∆Φ ≤ x + 2 · (−x + 2) = 4− x .

Change in Potential

7

24

26

52

17 23

30

18

21

35

39

5

ci = ci + ∆Φ ≤ O(x + 1) + 4− x = O(1)

Amortized Cost

Scale up potential units

First Coin pays cutSecond Coin increase of trees(H)

5.2: Fibonacci Heaps (Analysis) T.S. 5