Fibonacci Heap Group Minus One Second December 6, 2016 Group Minus - - PowerPoint PPT Presentation

fibonacci heap
SMART_READER_LITE
LIVE PREVIEW

Fibonacci Heap Group Minus One Second December 6, 2016 Group Minus - - PowerPoint PPT Presentation

Introduction Fibonacci Heap Time Complexity Analysis Fibonacci Heap Group Minus One Second December 6, 2016 Group Minus One Second Fibonacci Heap Introduction Fibonacci Heap Time Complexity Analysis Outline Introduction Motivation


slide-1
SLIDE 1 Introduction Fibonacci Heap Time Complexity Analysis

Fibonacci Heap

Group Minus One Second December 6, 2016

Group Minus One Second Fibonacci Heap
slide-2
SLIDE 2 Introduction Fibonacci Heap Time Complexity Analysis

Outline

Introduction Motivation Performance Goal Fibonacci Heap Structure Rank Insert Delete Min Decrease Key Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Group Minus One Second Fibonacci Heap
slide-3
SLIDE 3 Introduction Fibonacci Heap Time Complexity Analysis Motivation Performance Goal

Motivation

I Design a data structure that supports the following operations

I Insert(x) I DeleteMin() I DecreaseKey(u, v)

12 5 7 3 15 2 9 21 30

Group Minus One Second Fibonacci Heap
slide-4
SLIDE 4 Introduction Fibonacci Heap Time Complexity Analysis Motivation Performance Goal

Motivation

I Design a data structure that supports the following operations

I Insert(x) I DeleteMin() I DecreaseKey(u, v)

12 5 7 3 15 2 9 21 30 Insert(10) 10

Group Minus One Second Fibonacci Heap
slide-5
SLIDE 5 Introduction Fibonacci Heap Time Complexity Analysis Motivation Performance Goal

Motivation

I Design a data structure that supports the following operations

I Insert(x) I DeleteMin() I DecreaseKey(u, v)

12 5 7 3 15 2 9 21 30 DeleteMin() 10

Group Minus One Second Fibonacci Heap
slide-6
SLIDE 6 Introduction Fibonacci Heap Time Complexity Analysis Motivation Performance Goal

Motivation

I Design a data structure that supports the following operations

I Insert(x) I DeleteMin() I DecreaseKey(u, v)

12 5 7 3 15 9 21 30 DecreaseKey(21, 17) 10 17

Group Minus One Second Fibonacci Heap
slide-7
SLIDE 7 Introduction Fibonacci Heap Time Complexity Analysis Motivation Performance Goal

Performance Goal

I Our performance goals of this data structure

I Insert(x): O(1) I DeleteMin(): O(log n) I DecreaseKey(u, v): O(1) Group Minus One Second Fibonacci Heap
slide-8
SLIDE 8 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Structure

I Fibonacci heap is essentially a set of heap-ordered trees.

17 24 30 26 46 35 23 7 3 18 52 41 44 39 roots heap-ordered tree

Group Minus One Second Fibonacci Heap
slide-9
SLIDE 9 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Rank

I The rank of a tree in a Fibonacci heap is the number of

children of the root.

17 24 30 26 46 35 23 7 3 18 52 41 44 39 rank = 1 rank = 2 rank = 0 rank = 0 rank = 3

Group Minus One Second Fibonacci Heap
slide-10
SLIDE 10 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Insert

I To insert a new value x into Fibonacci Heap H, simply create

a new tree that contains only x and add it to H.

I Example: Insert(21)

17 24 30 26 46 35 23 7 3 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-11
SLIDE 11 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Insert

I To insert a new value x into Fibonacci Heap H, simply create

a new tree that contains only x and add it to H.

I Example: Insert(21)

17 24 30 26 46 35 23 7 3 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-12
SLIDE 12 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Delete Min

I The minimum must be one of the roots. I But there can be too many(Ω(n)) roots! I Example: DeleteMin() for the heap below

17 24 23 7 3 21 46

Group Minus One Second Fibonacci Heap
slide-13
SLIDE 13 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Delete Min

I We introduce consolidation, a process of merging trees of the

same rank.

17 24 30 26 46 35 23 7 3 18 52 41 44 39 21 merge

Group Minus One Second Fibonacci Heap
slide-14
SLIDE 14 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Delete Min

I We introduce consolidation, a process of merging trees of the

same rank.

17 24 30 26 46 35 23 7 3 18 52 41 44 39 21 merge

Group Minus One Second Fibonacci Heap
slide-15
SLIDE 15 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Delete Min

I We introduce consolidation, a process of merging trees of the

same rank.

17 24 30 26 46 35 23 7 3 18 52 41 44 39 21 merge

Group Minus One Second Fibonacci Heap
slide-16
SLIDE 16 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Delete Min

I We introduce consolidation, a process of merging trees of the

same rank.

17 24 30 26 46 35 23 7 3 18 52 41 44 39 21 merge

Group Minus One Second Fibonacci Heap
slide-17
SLIDE 17 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Delete Min

I We introduce consolidation, a process of merging trees of the

same rank.

17 24 30 26 46 35 23 7 3 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-18
SLIDE 18 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Delete Min

I After consolidation, we simply remove the minimum value and

leave the remaining trees in the heap.

17 24 30 26 46 35 23 7 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-19
SLIDE 19 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key

I Case 1: we can finish the operation immediately I Example: decreaseKey(46, 36)

17 24 30 26 46 35 23 7 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-20
SLIDE 20 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key

I Case 1: we can finish the operation immediately I Example: decreaseKey(46, 36)

17 24 30 26 36 35 23 7 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-21
SLIDE 21 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key

I Case 2: we have to cut the whole subtree rooted at u I Example: DecreaseKey(26, 16)

17 24 30 26 46 35 23 7 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-22
SLIDE 22 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key

I Case 2: we have to cut the whole subtree rooted at u I Example: DecreaseKey(26, 16)

17 24 30 16 46 35 23 7 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-23
SLIDE 23 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key

I Case 2: we have to cut the whole subtree rooted at u I Example: DecreaseKey(26, 16)

17 24 30 16 46 35 23 7 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-24
SLIDE 24 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key

I But wait! Under this strategy, something undesirable might

happen.

I The example below shows that this strategy can hurt the

performance of DeleteMin operation.

I Example:

Group Minus One Second Fibonacci Heap
slide-25
SLIDE 25 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

One node is marked if it has lost one of its children.

Group Minus One Second Fibonacci Heap
slide-26
SLIDE 26 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 1: no violation of heap property, finish.

Group Minus One Second Fibonacci Heap
slide-27
SLIDE 27 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 2: simply remove the subtree and mark the parent node.

Group Minus One Second Fibonacci Heap
slide-28
SLIDE 28 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 2: simply remove the subtree and mark the parent node.

Group Minus One Second Fibonacci Heap
slide-29
SLIDE 29 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 2: simply remove the subtree and mark the parent node.

Group Minus One Second Fibonacci Heap
slide-30
SLIDE 30 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 3: recursively remove all subtrees whose parent is marked.

Group Minus One Second Fibonacci Heap
slide-31
SLIDE 31 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 3: recursively remove all subtrees whose parent is marked.

Group Minus One Second Fibonacci Heap
slide-32
SLIDE 32 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 3: recursively remove all subtrees whose parent is marked.

Group Minus One Second Fibonacci Heap
slide-33
SLIDE 33 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 3: recursively remove all subtrees whose parent is marked.

Group Minus One Second Fibonacci Heap
slide-34
SLIDE 34 Introduction Fibonacci Heap Time Complexity Analysis Structure Rank Insert Delete Min Decrease Key

Decrease Key with Marks

Case 3: recursively remove all subtrees whose parent is marked.

Group Minus One Second Fibonacci Heap
slide-35
SLIDE 35 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Amortized Analysis

I We need a new technique to analyze the time complexity of

Fibonacci heap

I Consider the following question:

I Drop: Dropping a single coin onto a table costs 1 unit of time I Clean: Collecting each coin into a bag costs 1 unit of time.

Emptying the bag costs 1 unit of time.

I Question: What is the amortized time complexity of Clean
  • peration?
Group Minus One Second Fibonacci Heap
slide-36
SLIDE 36 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Amortized Analysis

I Observation: A coin that is cleaned must have been dropped

before.

I So why not prepay the cost of clean of each coin as the cost

  • f drop?

I Drop: Dropping a single coin onto a table costs 2 units of

time

I Clean: Collecting each coin into a bag costs no time.

Emptying the bag costs 1 unit of time.

I The amortized time complexity of Clean operation is O(1).

Group Minus One Second Fibonacci Heap
slide-37
SLIDE 37 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Insert Complexity

I In addition to the cost of creating a tree($1), we also add a

merge credit (a prepaid constant cost,$1) to each new tree.

I Since no other operations are needed, each Insert operation

still takes $2 = O(1) time.

17 24 23 7 3 21 46 $1 $1 $1 $1 $1 $1 $1

Group Minus One Second Fibonacci Heap
slide-38
SLIDE 38 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

I Recall that DeleteMin opeartion consists of two parts:

I Consolidate the heap: for each rank i ∈ [0, k], merge two

trees of the same rank i.

I Linearly search for the minimum: traverse all k + 1 roots. I k is the largest rank in the heap.

I We will make and prove a few claims.

Group Minus One Second Fibonacci Heap
slide-39
SLIDE 39 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

I Claim 1: Merge operations are free. I Proof: Their costs are paid by merge credits.

17 46 $1 $1 17 46 $1 The other $ 1 is usd to pay for the cost of merge

Group Minus One Second Fibonacci Heap
slide-40
SLIDE 40 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

I Claim 2: Consolidation operations are of O(k) where k is the

largest rank.

I Proof: For each rank i ∈ [0, k], consolidation calls merge to

generate new trees, which is free. So the only cost is the time consumed while travsering k + 1 ranks.

Group Minus One Second Fibonacci Heap
slide-41
SLIDE 41 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

I Claim 3: Searching for minimum is of O(k) where k is the

largest rank.

I Proof: After consolidation there are at most k + 1 roots. So

a linear traversal will take O(k) time.

17 24 30 26 46 35 23 7 3 18 52 41 44 39 21

Group Minus One Second Fibonacci Heap
slide-42
SLIDE 42 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

I Combining all three claims, we can see that the complexity of

DeleteMin is O(k) where k is the largest rank.

I One last question: why k = O(log n)?

I This is equivalent to ”what is the smallest number of nodes in

a tree of rank i?”

Group Minus One Second Fibonacci Heap
slide-43
SLIDE 43 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

Some results for different ranks. Let Si be the smallest number of nodes in a tree of rank i. We can see that S0 = 1, S1 = 2, S2 = 3, S3 = 5, S4 = 8, ...

rank = 0

Group Minus One Second Fibonacci Heap
slide-44
SLIDE 44 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

Some results for different ranks. Let Si be the smallest number of nodes in a tree of rank i. We can see that S0 = 1, S1 = 2, S2 = 3, S3 = 5, S4 = 8, ...

rank = 1

Group Minus One Second Fibonacci Heap
slide-45
SLIDE 45 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

Some results for different ranks. Let Si be the smallest number of nodes in a tree of rank i. We can see that S0 = 1, S1 = 2, S2 = 3, S3 = 5, S4 = 8, ...

rank = 2

Group Minus One Second Fibonacci Heap
slide-46
SLIDE 46 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

Some results for different ranks. Let Si be the smallest number of nodes in a tree of rank i. We can see that S0 = 1, S1 = 2, S2 = 3, S3 = 5, S4 = 8, ...

rank = 3

Group Minus One Second Fibonacci Heap
slide-47
SLIDE 47 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

Some results for different ranks. Let Si be the smallest number of nodes in a tree of rank i. We can see that S0 = 1, S1 = 2, S2 = 3, S3 = 5, S4 = 8, ...

rank = 4

Group Minus One Second Fibonacci Heap
slide-48
SLIDE 48 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Delete Min Complexity

I We can get a recurrence relation from the above observation:

Si = Si−1 + Si−2, S0 = 1, S1 = 2 which is exactly the Fibonacci sequence, and hence the heap’s name.

I Since Si ≥ ci where c = 1+ √ 5 2

, the number of nodes in each tree grows expoentially with the tree’s rank.

I Therefore, there can be at most O(log n) ranks in a Fibonacci

heap.

Group Minus One Second Fibonacci Heap
slide-49
SLIDE 49 Introduction Fibonacci Heap Time Complexity Analysis Amortized Analysis Insert Complexity Delete Min Complexity Decrease Key Complexity

Decrease Key Complexity

I By similar argument (using the amortized analysis), we can

prove that the time complexity of DecreaseKey(u, v) is O(1).

I We will omit this part due to time limit. I You can refer to the lecture note on the course website.

Group Minus One Second Fibonacci Heap
slide-50
SLIDE 50

Q& A

slide-51
SLIDE 51

Thank you