5

9

two weeks ⇡ 1 5 2 5 3 1 1 0 5 1 2 3 1 1 0 3 4 Finding Shortest Paths 1 s 3 4

Use of

X D B B B B Amortized Analysis T T T T T

PUSH(T) PUSH(B) PUSH(X) POP PUSH(D) MULTIPOP(3)

min next week

58 30 10

43 41 33 70 32 Fibonacci Heaps

54 66 82 51

5.2 Fibonacci Heaps Frank Stajano Thomas Sauerwald

Lent 2015

5.1: Amortized Analysis T.S. 2 Fibon. (1) O (1) O (1) O (log n) O (1) O (1) O (log n) O

Priority Queues Overview

Operation

MAKE-HEAP (1) (1) (1) O O O INSERT (1) (log n) (log n) O O O MINIMUM (n) (1) (log n) O O O EXTRACT-MIN (n) (log n) (log n) O O O MERGE (n) (n) (log n) O O O DECREASE-KEY (1) (log n) (log n) O O O DELETE (1) (log n) (log n) O O O

5.2: Fibonacci Heaps T.S. 2 Priority Queues Overview

Operation Linked list Binary heap Binomial heap Fibon. heap

MAKE-HEAP (1) (1) (1) (1) O O O O INSERT (1) (log n) (log n) (1) O O O O MINIMUM (n) (1) (log n) (1) O O O O EXTRACT-MIN (n) (log n) (log n) (log n) O O O O MERGE (n) (n) (log n) (1) O O O O DECREASE-KEY (1) (log n) (log n) (1) O O O O DELETE (1) (log n) (log n) (log n) O O O O

5.2: Fibonacci Heaps T.S. 2 actual cost amortized cost

All these cost bounds hold if n is the size of the heap.

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap.

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap actual cost amortized cost

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

5.2: Fibonacci Heaps T.S. 3 Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap actual cost amortized cost

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

All these cost bounds hold if n is the size of the heap.

5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. c = c = = c = (log n) 1 2 ··· k O Pk c = (k log n) ⇒ i=1 i O

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap actual cost amortized cost

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

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

5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap.

Pk c = (k log n) ⇒ i=1 i O

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap actual cost amortized cost

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

Binomial Heap: k/2 DECREASE-KEY + k/2 INSERT c = c = = c = (log n) 1 2 ··· k O

5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap.

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap actual cost amortized cost

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

Binomial Heap: k/2 DECREASE-KEY + k/2 INSERT c = c = = c = (log n) 1 2 ··· k O Pk c = (k log n) ⇒ i=1 i O 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap. c = c = = c = (1) e1 e2 ··· ek O Pk c Pk c = (k) ⇒ i=1 i ≤ i=1 ei O

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap actual cost amortized cost

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

Binomial Heap: k/2 DECREASE-KEY Fibonacci Heap: k/2 + k/2 INSERT DECREASE-KEY + k/2 INSERT c = c = = c = (log n) 1 2 ··· k O Pk c = (k log n) ⇒ i=1 i O 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap.

Pk c Pk c = (k) ⇒ i=1 i ≤ i=1 ei O

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap actual cost amortized cost

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

Binomial Heap: k/2 DECREASE-KEY Fibonacci Heap: k/2 + k/2 INSERT DECREASE-KEY + k/2 INSERT c = c = = c = (log n) c = c = = c = (1) 1 2 ··· k O e1 e2 ··· ek O Pk c = (k log n) ⇒ i=1 i O 5.2: Fibonacci Heaps T.S. 3 All these cost bounds hold if n is the size of the heap.

Binomial Heap vs. Fibonacci Heap: Costs

Operation Binomial heap Fibonacci heap actual cost amortized cost

MAKE-HEAP (1) (1) O O INSERT (log n) (1) O O MINIMUM (log n) (1) O O EXTRACT-MIN (log n) (log n) O O MERGE (log n) (1) O O DECREASE-KEY (log n) (1) O O DELETE (log n) (log n) O O

Binomial Heap: k/2 DECREASE-KEY Fibonacci Heap: k/2 + k/2 INSERT DECREASE-KEY + k/2 INSERT c = c = = c = (log n) c = c = = c = (1) 1 2 ··· k O e1 e2 ··· ek O Pk c = (k log n) Pk c Pk c = (k) ⇒ i=1 i O ⇒ i=1 i ≤ i=1 ei O 5.2: Fibonacci Heaps T.S. 3 Pk Pk i=1 eci i=1 ci

Potential

Potential 0, but should be ≥ also as small as possible

Actual vs. Amortized Cost

14 (1) ·O

2 (1) ·O (1) O k 0 1 2 14

5.2: Fibonacci Heaps T.S. 4 Pk i=1 ci

Potential

Potential 0, but should be ≥ also as small as possible

Actual vs. Amortized Cost

Pk i=1 eci 14 (1) ·O

2 (1) ·O (1) O k 0 1 2 14

5.2: Fibonacci Heaps T.S. 4 Potential

Potential 0, but should be ≥ also as small as possible

Actual vs. Amortized Cost

Pk Pk i=1 eci i=1 ci 14 (1) ·O

2 (1) ·O (1) O k 0 1 2 14

5.2: Fibonacci Heaps T.S. 4 Potential 0, but should be ≥ also as small as possible

Actual vs. Amortized Cost

Pk Pk i=1 eci i=1 ci 14 (1) ·O

Potential

2 (1) ·O (1) O k 0 1 2 14

5.2: Fibonacci Heaps T.S. 4 Actual vs. Amortized Cost

Pk Pk i=1 eci i=1 ci 14 (1) ·O

Potential

Potential 0, but should be 2 (1) ≥ ·O also as small as possible (1) O k 0 1 2 14

5.2: Fibonacci Heaps T.S. 4 Outline

Structure

Operations

Glimpse at the Analysis

5.2: Fibonacci Heaps T.S. 5 MERGE: Merge two binomial heaps using Binary Addition Procedure INSERT: Add B(0) and perform a MERGE EXTRACT-MIN: Find with minimum key, cut it and perform a MERGE DECREASE-KEY: The same as in a binary heap

Operations:

Reminder: Binomial Heaps

Binomial Trees

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

B(k 1) − B(k 1) −

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

5.2: Fibonacci Heaps T.S. 6 MERGE: Merge two binomial heaps using Binary Addition Procedure INSERT: Add B(0) and perform a MERGE EXTRACT-MIN: Find tree with minimum key, cut it and perform a MERGE DECREASE-KEY: The same as in a binary heap

Reminder: Binomial Heaps

Binomial Trees

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

B(k 1) − B(k 1) −

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

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 Heaps 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 Procedure INSERT: Add B(0) and perform a MERGE EXTRACT-MIN: Find tree with minimum key, cut it and perform a MERGE DECREASE-KEY: The same as in a binary heap

5.2: Fibonacci Heaps T.S. 6 1 3 5 2

4 9 11 6 3 8 75 14 15

12 17 13 610 8 7 51418

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 3 5 2

4 9 11 6 3 8 75 14 15

12 17 13 610 8 7 51418

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 3 5 2

4 9 11 6 3 8 75 14 15

12 17 13 610 8 7 51418

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 3 5

4 9 11 6 3 8 75 14

12 17 13 610 8 7 51418

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

2

15

0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 3 5

4 9 11 6 3 8 75 14

12 17 13 610 8 7 51418

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

2

15

0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 3 5

4 9 11 6 3 8 75 14

12 17 13 610 8 7 51418

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

2

15

0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 3

4 9 11 6 3 8 5

12 17 13 610 8 7 514

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

5 2

7 14 15

18 0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 3

4 9 11 6 3 8 5

12 17 13 610 8 7 514

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

5 2

7 14 15

18 0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 3

4 9 11 6 3 8 5

12 17 13 610 8 7 514

16 10 718 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

5 2

7 14 15

18 0 0 1 1 1 = 7 0 1 0 1 1 = 11 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 5

4 9 11 3 7 14

12 17 13 6 8 518

16 10 7 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

3 2

6 8 5 15

10 7 14 0 0 1 1 1 = 7 0 1 0 1 1 = 11 18 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 5

4 9 11 3 7 14

12 17 13 6 8 518

16 10 7 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

3 2

6 8 5 15

10 7 14 0 0 1 1 1 = 7 0 1 0 1 1 = 11 18 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 1 5

4 9 11 3 7 14

12 17 13 6 8 518

16 10 7 14

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

3 2

6 8 5 15

10 7 14 0 0 1 1 1 = 7 0 1 0 1 1 = 11 18 1 1 1 1 1 0 0 1 0 = 18

5.2: Fibonacci Heaps T.S. 7 3 5

6 8 75 14

10 7 1418

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

1 2

4 9 11 3 15

12 17 13 6 8 5 0 0 1 1 1 = 7 0 1 0 1 1 = 11 16 10 7 14 1 1 1 1 1 0 0 1 0 = 18 18

5.2: Fibonacci Heaps T.S. 7 3 5

6 8 75 14

10 7 1418

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

1 2

4 9 11 3 15

12 17 13 6 8 5 0 0 1 1 1 = 7 0 1 0 1 1 = 11 16 10 7 14 1 1 1 1 1 0 0 1 0 = 18 18

5.2: Fibonacci Heaps T.S. 7 3 5

6 8 75 14

10 7 1418

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

1 2

4 9 11 3 15

12 17 13 6 8 5 0 0 1 1 1 = 7 0 1 0 1 1 = 11 16 10 7 14 1 1 1 1 1 0 0 1 0 = 18 18

5.2: Fibonacci Heaps T.S. 7 3 5

6 8 75 14

10 7 1418

18

Merging two Binomial Heaps

3 5 15 1 14 2

6 8 7 + 4 9 11 18 10 12 17 13

16

1 2

4 9 11 3 15

12 17 13 6 8 5 0 0 1 1 1 = 7 0 1 0 1 1 = 11 16 10 7 14 1 1 1 1 1 0 0 1 0 = 18 18

5.2: Fibonacci Heaps T.S. 7 Fibonacci Heap: forest of MIN-HEAPs lazily defer tidying up; do it on-the-fly when search for the MIN

37 22 5 51

50 38 26 19 7 30

66 48

Binomial Heap vs. Fibonacci Heap: Structure

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

5 7

38 51 50 26 22

63 37 30 48

54

5.2: Fibonacci Heaps T.S. 8 Binomial Heap vs. Fibonacci Heap: Structure

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

5 7

38 51 50 26 22

63 37 30 48

54

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

37 22 5 51

50 38 26 19 7 30

66 48

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

min

41 70

How do we implement a Fibonacci Heap?

Structure of Fibonacci Heaps

Fibonacci Heap Forest of MIN-HEAPs

58 30 10

43 41 33 70 32

54 66 82 51

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

min

41 70

How do we implement a Fibonacci Heap?

Structure of Fibonacci Heaps

Fibonacci Heap Forest of MIN-HEAPs

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 9 Tree roots are stored in a circular, doubly-linked list Min-Pointer pointing to the smallest element

min

41 70

How do we implement a Fibonacci Heap?

Structure of Fibonacci Heaps

Fibonacci Heap Forest of MIN-HEAPs Nodes can be marked(roots are always unmarked)

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 9 Tree roots are stored in a circular, doubly-linked list Min-Pointer pointing to the smallest element

min

41 70

How do we implement a Fibonacci Heap?

Structure of Fibonacci Heaps

Fibonacci Heap Forest of MIN-HEAPs Nodes can be marked(roots are always unmarked)

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 9 Min-Pointer pointing to the smallest element

min

41 70

How do we implement a Fibonacci Heap?

Structure of Fibonacci Heaps

Fibonacci Heap Forest of MIN-HEAPs Nodes can be marked(roots are always unmarked) Tree roots are stored in a circular, doubly-linked list

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 9 Min-Pointer pointing to the smallest element

min

41 70

How do we implement a Fibonacci Heap?

Structure of Fibonacci Heaps

Fibonacci Heap Forest of MIN-HEAPs Nodes can be marked(roots are always unmarked) Tree roots are stored in a circular, doubly-linked list

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 9 min

41 70

How do we implement a Fibonacci Heap?

Structure of Fibonacci Heaps

Fibonacci Heap 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

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 9 41 70

How do we implement a Fibonacci Heap?

Structure of Fibonacci Heaps

Fibonacci Heap 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

min

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 9 41 70

Structure of Fibonacci Heaps

Fibonacci Heap 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

min

58 30 10

43 41 33 70 32

54 66 82 51

How do we implement a Fibonacci Heap?

5.2: Fibonacci Heaps T.S. 9 A single Node

Parent

p

b payload marked degree f Previous Sibling Next Sibling 0 3

c

One of the Children

5.2: Fibonacci Heaps T.S. 10 58 10 30 0 3

43 0 0 41 1 2 33 0 1

54 82

Magnifying a Four-Node Portion

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 11 58 10 30 0 3

43 0 0 41 1 2 33 0 1

54 82

Magnifying a Four-Node Portion

58 30 10

43 41 33 70 32

54 66 82 51

5.2: Fibonacci Heaps T.S. 11 Magnifying a Four-Node Portion

58 30 10

58 10 43 41 33 70 32 30 0 3

54 66 82 51

43 0 0 41 1 2 33 0 1

54 82

5.2: Fibonacci Heaps T.S. 11 Outline

Structure

Operations

Glimpse at the Analysis

5.2: Fibonacci Heaps T.S. 12 and update min-pointer (if necessary)

Create a singleton tree Add to root list

21

Actual Costs: O(1) min

21

Fibonacci Heap: INSERT

INSERT

21

17 24 23 7 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 13 and update min-pointer (if necessary)

Add to root list

21

Actual Costs: O(1) min

21

Fibonacci Heap: INSERT

INSERT Create a singleton tree

21

17 24 23 7 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 13 and update min-pointer (if necessary)

21

Actual Costs: O(1) min

Fibonacci Heap: INSERT

INSERT Create a singleton tree Add to root list

21

17 24 23 7 21 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 13 and update min-pointer (if necessary)

21

Actual Costs: O(1) min

Fibonacci Heap: INSERT

INSERT Create a singleton tree Add to root list

21

17 24 23 7 21 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 13 21

Actual Costs: O(1)

Fibonacci Heap: INSERT

INSERT Create a singleton tree Add to root list and update min-pointer (if necessary)

21

min

17 24 23 7 21 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 13 21

Fibonacci Heap: INSERT

INSERT Create a singleton tree Add to root list and update min-pointer (if necessary)

21

Actual Costs: O(1) min

17 24 23 7 21 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 13 X X (# children) X X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

41

44

Delete min Meld childen into root list and unmark them Consolidate so that no roots have the same degree Update minimum

degree 0 1 2 3 Actual Costs: min 1 degree=22 0 degree=00 1 0 1

17 18 52

17 24 23 41 39

23 26 46 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN

min

7 24 23 17 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 14 X (# children) X X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

41

44

X Meld childen into root list and unmark them Consolidate so that no roots have the same degree Update minimum

degree 0 1 2 3 Actual Costs: min 1 degree=22 0 degree=00 1 0 1

17 18 52

17 24 23 41 39

23 26 46 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min

min

7 24 23 17 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 14 X (# children) X X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

41

44

Meld childen into root list and unmark them Consolidate so that no roots have the same degree Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 18 52

17 24 23 41 39

23 26 46 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X

7 24 23 17 3

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 14 (# children) X X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

41

44

X Consolidate so that no roots have the same degree Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 183 52

17 24 23 41 39

23 26 46 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them

7 24 23 17

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 14 (# children) X X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

41

44

X Consolidate so that no roots have the same degree Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 183 52

17 24 23 41 39

23 26 46 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them

7 24 23 17

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 14 (# children) X X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

41

44

X Consolidate so that no roots have the same degree Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 183 52

17 24 23 41 39

23 26 46 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them

7 24 23 17

30 26 46 18 52 41

35 39 44

5.2: Fibonacci Heaps T.S. 14 (# children) X X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

Consolidate so that no roots have the same degree Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

(# children) X Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

degree 0 1 2 3 Actual Costs: min min 1 2 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree=2

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 0 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree=0

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

degree 0 1 2 3 Actual Costs: min min degree=2 degree=0

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

1 2 0 0 1 0 1

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

17 3

17 24 23 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 23 17 18 52 41

30 26 46 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

23 17 3

17 24 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 17 18 52 41

30 26 46 23 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

23 17 3

17 24 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 17 18 52 41

30 26 46 23 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

23 17 3

17 24 41 18 52 41

23 26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 17 18 52 41

30 26 46 23 39 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

23 17 17 3

24 23 41 18 52 41

26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 18 52 41

17 30 26 46 39 44

23 35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

23 17 17 3

24 23 41 18 52 41

26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 18 52 41

17 30 26 46 39 44

23 35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

23 17 17 3

24 23 41 18 52 41

26 46 44 39 44

35

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 24 18 52 41

17 30 26 46 39 44

23 35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3

26 46 23 41 18 52 41

35 44 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52 41

17 30 24 39 44

23 26 46

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

EXTRACT-MIN Delete min X Meld childen into root list and unmark them X Consolidate so that no roots have the same degree (# children)

degree 0 1 2 3

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 X d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

Update minimum

Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

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

degree 0 1 2 3

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

X

degree 0 1 2 3 Actual Costs: min min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

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

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 d(n) is the maximum degree of a Every root becomes child of another root at most once! root in any Fibonacci heap of size n

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

degree 0 1 2 3 Actual Costs: min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

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

min

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 d(n) is the maximum degree of a Every root becomes child of another root at most once! degreeroot in any Fibonacci heap of size n 0 1 2 3 O(trees(H) + d(n)) min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

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

Actual Costs: min

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 d(n) is the maximum degree of a degreeroot in any Fibonacci heap of size n 0 1 2 3 O(trees(H) + d(n)) min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

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

Every root becomes child of another root at most once!

Actual Costs: min

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 Every root becomes child of another root at most once! degree 0 1 2 3

min 1 degree=22 0 degree=00 1 0 1

24 23 17 17 3 41

26 46 23 18 52 41 44

35 39 44

Fibonacci Heap: EXTRACT-MIN

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 d(n) is the maximum degree of a root in any Fibonacci heap of size n

Actual Costs: O(trees(H) + d(n)) min

7 18 52

17 30 24 41 39

23 26 46 44

35

5.2: Fibonacci Heaps T.S. 14 , then done. cut tree rooted at x and meld into root list (update min).

If not Otherwise,

Check if heap-order is violated

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

20 20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer)

min

7 18 38

24 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 , then done. cut tree rooted at x and meld into root list (update min).

If not Otherwise,

Check if heap-order is violated

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

20 20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer)

min

7 18 38

24 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 , then done. cut tree rooted at x and meld into root list (update min).

If not Otherwise,

Check if heap-order is violated

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer)

min

7 18 38

24 20 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 , then done. cut tree rooted at x and meld into root list (update min).

If not Otherwise,

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

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

min

7 18 38

20 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 , then done. cut tree rooted at x and meld into root list (update min).

If not Otherwise,

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

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

min

7 18 38

20 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 cut tree rooted at x and meld into root list (update min).

, then done. Otherwise,

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer) Check if heap-order is violated If not

min

7 18 38

20 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 cut tree rooted at x and meld into root list (update min).

Otherwise,

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer) Check if heap-order is violated If not, then done.

min

7 18 38

20 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 cut tree rooted at x and meld into root list (update min).

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer) Check if heap-order is violated If not, then done. Otherwise,

min

7 18 38

20 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 cut tree rooted at x and meld into root list (update min).

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 15 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer) Check if heap-order is violated If not, then done. Otherwise,

min

7 18 38

20 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 15 cut tree rooted at x and meld into root list (update min).

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 15 12 19 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer) Check if heap-order is violated If not, then done. Otherwise,

min

7 18 38

20 17 23 21 39 41

26 46 30 52 15 35

5.2: Fibonacci Heaps T.S. 15 cut tree rooted at x and meld into root list (update min).

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 46 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer) Check if heap-order is violated If not, then done. Otherwise,

min

7 18 38

20 17 23 21 39 41

26 15 30 52

35

5.2: Fibonacci Heaps T.S. 15 cut tree rooted at x and meld into root list (update min).

Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 46 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x Decrease the key of x (given by a pointer) Check if heap-order is violated If not, then done. Otherwise,

min

7 18 38

20 17 23 21 39 41

26 15 30 52

35

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

15 5 19 12

24 20

19 46 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38

20 17 23 21 39 41

26 15 30 52

35

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

5 19 12

24 20

19 4615 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15

20 17 23 21 39 41

26 30 52

35

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

5 19 12

24 20

19 4615 12 19 15 12 Wide and 5 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15

20 17 23 21 39 41

26 30 52

35

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

5 19 12

24 20

19 4615 12 19 15 12 Wide and 5 shallow tree

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15

20 17 23 21 39 41

26 30 52

35 5

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

5 19 12

24 20

19 4615 12 19 15 12 Wide and 35 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15

20 17 23 21 39 41

26 30 52

5

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

5 19 12

24 20

19 4615 12 19 15 12 Wide and 35 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15

20 17 23 21 39 41

26 30 52

5

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root Nodes =node4 loses at most one child before becomingmin root

5 19 12

24 20

19 4615 12 19 15 12 Wide and 35 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15

20 17 23 21 39 41

26 30 52

5

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

19 12

24 20

19 4615 12 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5

20 17 23 21 39 41

26 30 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

19 12

24 20

19 4615 12 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5

20 17 23 21 39 41

26 30 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

19 12

24 20

19 4615 12 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5

20 17 23 21 39 41

26 30 52 19

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

19 12

24 20

26 4615 12 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5

20 17 23 21 39 41

19 30 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

19 12

24 20

26 4615 12 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5

20 17 23 21 39 41

19 30 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

19 12

24 20

26 4615 12 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5

20 17 23 21 39 41

19 30 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

12

24 20

2619 4615 12 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19

20 17 23 21 39 41

30 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

12

24 20

2619 4615 12 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19

20 17 23 21 39 41

30 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

12

24 20

2619 4615 12 19 15 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19

20 17 23 21 39 41

30 52 12

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

12

24 20

2619 4615 30 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19

20 17 23 21 39 41

12 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

12

24 20

2619 4615 30 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19

20 17 23 21 39 41

12 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

12

24 20

2619 4615 30 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19

20 17 23 21 39 41

12 52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

24 20

2619 4615 1230 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19 12

20 17 23 21 39 41

52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

24 20

2619 4615 1230 19 15 12 Wide and 355 shallow tree 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19 12

20 17 23 21 39 41

52

5.2: Fibonacci Heaps T.S. 15 Degree Peculiar= 3, Constraint: Make sure that each non-root minNodes =node4 loses at most one child before becoming root

24 20

2619 4615 1230 19 15 12 355 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

min

7 18 38 15 5 19 12

20 17 23 21 39 41

52

Wide and shallow tree

5.2: Fibonacci Heaps T.S. 15 Peculiar Constraint: Make sure that each non-root min node loses at most one child before becoming root

24 20

2619 4615 1230 19 15 12 355 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

Degree = 3, Nodes = 4 min

7 18 38 15 5 19 12

20 17 23 21 39 41

52

Wide and shallow tree

5.2: Fibonacci Heaps T.S. 15 Degree = 3, minNodes = 4

24 20

2619 4615 1230 19 15 12 355 5

Fibonacci Heap: DECREASE-KEY (First Attempt)

DECREASE-KEY of node x 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).

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

7 18 38 15 5 19 12

20 17 23 21 39 41

52

Wide and shallow tree

5.2: Fibonacci Heaps T.S. 15 unmark and meld it into root list and recurse (Cascading Cut)

and:

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

O(# cuts)

X X

(Here we consider only cases where heap-order is violated) Cut tree rooted at x, unmark x, meld into root list ⇒ Check if parent node is marked

Actual Cost: min

7 15 5 26 24

24

15 15 1.D ECREASE-KEY 46 15 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x Decrease the key of x (given by a pointer)

min

7 18 38

24 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

and:

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

O(# cuts)

X

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

Actual Cost: min

7 15 5 26 24

24

15 15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x Decrease the key of x (given by a pointer) (Here we consider only cases where heap-order is violated)

min

7 18 38

24 17 23 21 39 41

26 46 30 52 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

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

O(# cuts)

X

and: Check if parent node is marked

Actual Cost: min

7 15 5 26 24

24

15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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 ⇒

min

7 18 38

24 17 23 21 39 41

26 46 30 52 15 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

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

O(# cuts)

X

and: Check if parent node is marked

Actual Cost: min

7 15 5 26 24

24

46 15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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 ⇒

min

7 18 38

24 17 23 21 39 41

26 15 30 52 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

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

O(# cuts)

X

and: Check if parent node is marked

Actual Cost: min

7 15 5 26 24

24

46 15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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 ⇒

min

7 18 38

24 17 23 21 39 41

26 15 30 52 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

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

O(# cuts)

X

and: Check if parent node is marked

Actual Cost: min

7 15 5 26 24

24

46 15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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 ⇒

min

7 18 38

24 17 23 21 39 41

26 15 30 52 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

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

O(# cuts)

X

Check if parent node is marked

Actual Cost: min

7 5 26 24

24

46 15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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: ⇒

min

7 18 38 15

24 17 23 21 39 41

26 15 30 52 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

X

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

Actual Cost: min

7 5 26 24

24

46 15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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

min

7 18 38 15

24 17 23 21 39 41

26 15 30 52 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

X

If marked,

Actual Cost: min

7 5 26 24

24

46 15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15

24 17 23 21 39 41

26 15 30 52 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

X

If marked,

Actual Cost: min

7 5 26 24

46 15 X 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15

24 17 23 21 39 41

26 15 30 52 1.D ECREASE-KEY 46 15 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

X

If marked,

Actual Cost: min

7 5 26 24

4615 15 5 2.D ECREASE-KEY 35 5 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 35

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

If marked,

Actual Cost: min

7 5 26 24

4615 15 5 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 35 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

If marked,

Actual Cost: min

7 5 26 24

4615 15 5 X

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 35 2.D ECREASE-KEY 35 5 5

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

If marked,

Actual Cost: min

7 5 26 24

4615 15 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 355 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

If marked,

Actual Cost: min

7 5 26 24

4615 15 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 355 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

If marked,

Actual Cost: min

7 5 26 24

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 unmark and meld it into root list and recurse (Cascading Cut)

O(# cuts)

If marked,

Actual Cost: min

7 26 24

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

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

min Actual Cost:

7 26 24

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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,

min

7 18 38 15 5

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

min Actual Cost:

7 26 24

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

min Actual Cost:

7 24

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5 26

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

min Actual Cost:

7 24

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5 26

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

min Actual Cost:

7 24

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5 26

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

min Actual Cost:

7

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5 26 24

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

min Actual Cost:

7

4615 15 35 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5 26 24

24 17 23 21 39 41

26 30 52 1.D ECREASE-KEY 46 15 X 5 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

min Actual Cost:

7

24

26 4615 15 355 X 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5 26 24

17 23 21 39 41

30 52 1.D ECREASE-KEY 46 15 X 2.D ECREASE-KEY 35 5

5.2: Fibonacci Heaps T.S. 16 O(# cuts)

min Actual Cost:

7

24

26 4615 15 355 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

min

7 18 38 15 5 26 24

17 23 21 39 41

30 52 1.D ECREASE-KEY 46 15 X 2.D ECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16 min O(# cuts)

7

24

26 4615 15 355 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

Actual Cost: min

7 18 38 15 5 26 24

17 23 21 39 41

30 52 1.D ECREASE-KEY 46 15 X 2.D ECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16 min

7

24

26 4615 15 355 5

Fibonacci Heap: DECREASE-KEY

DECREASE-KEY of node x 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)

Actual Cost: O(# cuts) min

7 18 38 15 5 26 24

17 23 21 39 41

30 52 1.D ECREASE-KEY 46 15 X 2.D ECREASE-KEY 35 5 X

5.2: Fibonacci Heaps T.S. 16 Outline

Structure

Operations

Glimpse at the Analysis

5.2: Fibonacci Heaps T.S. 17 Lifecycle of a node

26 Consolidate

Loses second child

26 26

Loses first child

amortized (1) O amortized (d(n)) O amortized (1) O

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

7 18 38

24 17 23 21 39 41

26 46 30 52

35

Amortized Analysis via

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

5.2: Fibonacci Heaps T.S. 18 Lifecycle of a node

26 Consolidate

Loses second child

26 26

Loses first child

amortized (1) O amortized (d(n)) O amortized (1) O

7 18 38

24 17 23 21 39 41

26 46 30 52

35

Amortized Analysis via Potential Method

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

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

5.2: Fibonacci Heaps T.S. 18 amortized (1) O amortized (d(n)) O amortized (1) O

Lifecycle of a node

26 Consolidate

Loses second child

26 26

Loses first child

Amortized Analysis via Potential Method

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

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

7 18 38

24 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 18 amortized (1) O amortized (d(n)) O amortized (1) O

Lifecycle of a node

26 Consolidate

Loses second child

26 26

Loses first child

Amortized Analysis via Potential Method

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

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

7 18 38

24 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 18 amortized (1) O amortized (d(n)) O amortized (1) O

Lifecycle of a node

26 Consolidate

Loses second child

26 26

Loses first child

Amortized Analysis via Potential Method

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

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

7 18 38

24 17 23 21 39 41

26 46 30 52

35

5.2: Fibonacci Heaps T.S. 18 Amortized Analysis via Potential Method

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

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

Lifecycle of a node

7 18 38 26 Consolidate

24 17 23 21 39 41

Loses second child 26 46 30 52 26 26

35 Loses first child

5.2: Fibonacci Heaps T.S. 18