fibonacci heap - sjtudominik/teaching/2016-cs217/...2016/12/21  · let x be any node in a fibonacci...

21
Fibonacci Heap Group Paradox December 21, 2016

Upload: others

Post on 08-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Fibonacci Heap

Group Paradox

December 21, 2016

Page 2: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Contents

1. Introduction

2. Operations

3. Why it called Fibonacci (the proof)

Page 3: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Priority Queue in Dijkstra

Page 4: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Fibonacci Heap

Operation Binary Heap Fibonacci Heap

Find-Min O(1) O(1)

Insert O(lg(n)) O(1)

Extract-Min O(lg(n)) O(lg(n))

Decrease-Key O(lg(n)) O(1)

Merge O(n) O(1)

Page 5: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Structure

root listlink a bunch of trees

minimum pointer

Page 6: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Insert

Just add them into the root list

Page 7: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Extract-Min

1. extract the minimum X

2. add the children of X to the root list

3. consolidate (make the degree of nodes unique)

4. find the new minimum

Page 8: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Amortized Analysis

I we pay one coin for every re-link operation.

I a coin takes O(1) time

I requirement : every root has a coin

I deposit a coin on new node when we insert it to meet therequirement

I we can use these coins during the consolidation,so consolidation costs no new coin

I Extract-Min only needs at most O(max degree) coins forre-linking children and finding new minimum

Page 9: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Amortized Analysis

I we pay one coin for every re-link operation.

I a coin takes O(1) time

I requirement : every root has a coin

I deposit a coin on new node when we insert it to meet therequirement

I we can use these coins during the consolidation,so consolidation costs no new coin

I Extract-Min only needs at most O(max degree) coins forre-linking children and finding new minimum

Page 10: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Amortized Analysis

I we pay one coin for every re-link operation.

I a coin takes O(1) time

I requirement : every root has a coin

I deposit a coin on new node when we insert it to meet therequirement

I we can use these coins during the consolidation,so consolidation costs no new coin

I Extract-Min only needs at most O(max degree) coins forre-linking children and finding new minimum

Page 11: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Amortized Analysis

I we pay one coin for every re-link operation.

I a coin takes O(1) time

I requirement : every root has a coin

I deposit a coin on new node when we insert it to meet therequirement

I we can use these coins during the consolidation,so consolidation costs no new coin

I Extract-Min only needs at most O(max degree) coins forre-linking children and finding new minimum

Page 12: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Amortized Analysis

I we pay one coin for every re-link operation.

I a coin takes O(1) time

I requirement : every root has a coin

I deposit a coin on new node when we insert it to meet therequirement

I we can use these coins during the consolidation,so consolidation costs no new coin

I Extract-Min only needs at most O(max degree) coins forre-linking children and finding new minimum

Page 13: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Amortized Analysis

I we pay one coin for every re-link operation.

I a coin takes O(1) time

I requirement : every root has a coin

I deposit a coin on new node when we insert it to meet therequirement

I we can use these coins during the consolidation,so consolidation costs no new coin

I Extract-Min only needs at most O(max degree) coins forre-linking children and finding new minimum

Page 14: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Note that one coin takes O(1) amortized cost

Operation Coin Needed at most Amortized Cost

Insert 2 O(1)

Extract-Min (2 + 1) ·maxdegree O(lg(n))

LemmaThe maximum degree of nodes in a Fibonacci heap is O(lg(n))

Page 15: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

The Idea of Amortized Analysis

......

... ...insert extract-min

Running Time Running Time

insert insert insert insert extract-mininsert insert insert

Page 16: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Decrease-Key

1. cut it to the root list

2. make the cascading cut

Page 17: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Coin Analysis

Cut a node to root costs 2 coin, mark a node costs 2 coins.

Operation Coin Needed at most Amortized Cost

Insert 2 O(1)

Extract-Min (2 + 1) ·maxdegree O(lg(n))

Decrease-Key 4 O(1)

Page 18: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Delete

1. decrease it to −∞2. extract the minimum

I amortized cost is O(1) + O(lg(n)) = O(lg(n))

Page 19: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Why it called Fibonacci

Lemma : Bounding the Maximum DegreeLet x be any node in a Fibonacci heap, and let k = x .degree.Then size(x) ≥ Fk+2

Proofrecall two lemmas about the Fibonacci number

Fk+2 ≤ φk and Fk =∑k−2

0 Fi + 1Let Sk be the possible minimum size of any nodes of degree k ,

we can derive

Sk ≥k−2∑0

Si + 1

thus, Sk ≥ Fk+2

Page 20: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Why it called Fibonacci

Lemma : Bounding the Maximum DegreeLet x be any node in a Fibonacci heap, and let k = x .degree.Then size(x) ≥ Fk+2

Proofrecall two lemmas about the Fibonacci number

Fk+2 ≤ φk and Fk =∑k−2

0 Fi + 1Let Sk be the possible minimum size of any nodes of degree k ,

we can derive

Sk ≥k−2∑0

Si + 1

thus, Sk ≥ Fk+2

Page 21: Fibonacci Heap - SJTUdominik/teaching/2016-cs217/...2016/12/21  · Let x be any node in a Fibonacci heap, and let k = x:degree. Then size(x) F k+2 Proof recall two lemmas about the

Why it called Fibonacci

Lemma : Bounding the Maximum DegreeLet x be any node in a Fibonacci heap, and let k = x .degree.Then size(x) ≥ Fk+2

Proofrecall two lemmas about the Fibonacci number

Fk+2 ≤ φk and Fk =∑k−2

0 Fi + 1Let Sk be the possible minimum size of any nodes of degree k ,

we can derive

Sk ≥k−2∑0

Si + 1

thus, Sk ≥ Fk+2