Fibonacci Heaps
-
Upload
naseeba-p-p -
Category
Education
-
view
684 -
download
1
Transcript of Fibonacci Heaps
![Page 1: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/1.jpg)
1
Fibonacci Heaps
Created by:Naseeba P P
![Page 2: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/2.jpg)
2
What is a Fibonacci Heap?• Heap ordered Trees.• Rooted, but unordered.• Children of a node are linked together in a Circular,
doubly linked List.• Collection of unordered Binomial Trees.• Support Mergeable heap operations such as Insert,
Minimum, Extract Min, and Union in constant time O(1).• Desirable when the number of Extract Min and Delete
operations are small relative to the number of other operations.
![Page 3: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/3.jpg)
3
Cont..
Node Pointers - left [x] - right [x] - degree [x] - number of children in the child list of x - - mark [x]
![Page 4: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/4.jpg)
4
Fibonacci Heap Operations
• Insertion• Linking operation• Extract Minimum Node• Decrease key• Delete
![Page 5: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/5.jpg)
5
Insert
• Create a new singleton tree.
![Page 6: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/6.jpg)
6
Cont..
• Add to root list; update min pointer (if necessary).• Increment the total number of nodes in the Heap,
n[H].
![Page 7: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/7.jpg)
7
Insert: Algorithm
![Page 8: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/8.jpg)
8
Insert Analysis
• Actual cost. O(1)• Change in potential. +1• Amortized cost. O(1)• Potential of heap H
(H) = trees(H) + 2 marks(H)
![Page 9: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/9.jpg)
9
Union
• Combine two Fibonacci heaps
![Page 10: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/10.jpg)
10
Cont..
![Page 11: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/11.jpg)
11
Union: Algorithm
![Page 12: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/12.jpg)
12
Union Analysis
• Potential function
•Actual cost. O(1) • Change in potential. 0• Amortized cost. O(1)
(H) = trees(H) + 2 marks(H)
![Page 13: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/13.jpg)
13
Delete or Extract Min
• Delete minimum
![Page 14: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/14.jpg)
14
Cont..
• Meld its children into root list.• Update minimum.
![Page 15: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/15.jpg)
15
Cont..
• Consolidate trees so that no two roots have same rank.
![Page 16: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/16.jpg)
16
Cont..
current
![Page 17: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/17.jpg)
17
Cont..
current
![Page 18: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/18.jpg)
18
Cont..
current
![Page 19: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/19.jpg)
19
Cont..
current
![Page 20: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/20.jpg)
20
Cont..
current
Link 23 into 17
![Page 21: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/21.jpg)
21
Cont..
Link 17 into 7
![Page 22: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/22.jpg)
22
Cont..
Link 24 into 7
![Page 23: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/23.jpg)
23
Cont..
current
![Page 24: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/24.jpg)
24
Cont..
current
![Page 25: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/25.jpg)
25
Cont..
current
![Page 26: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/26.jpg)
26
Cont..
current
Link 41 into 18
![Page 27: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/27.jpg)
27
Cont..
![Page 28: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/28.jpg)
28
Cont..
![Page 29: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/29.jpg)
29
Cont..
Stop
![Page 30: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/30.jpg)
30
Delete Min: Algorithm
![Page 31: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/31.jpg)
31
Cont..
![Page 32: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/32.jpg)
32
Cont..
![Page 33: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/33.jpg)
33
Delete Min AnalysisDelete min.
Actual cost. O(rank(H)) + O(trees(H)) O(rank(H)) to meld min's children into root list.O(rank(H)) + O(trees(H)) to update min.O(rank(H)) + O(trees(H)) to consolidate trees.
Change in potential. O(rank(H)) - trees(H)trees(H' ) rank(H) + 1 since no two trees have same rank.(H) rank(H) + 1 - trees(H).
Amortized cost. O(rank(H))
(H) = trees(H) + 2 marks(H)
Potential function
![Page 34: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/34.jpg)
34
Decrease Key• Intuition for deceasing the key of node x.• If heap-order is not violated, just decrease the key of x.• Otherwise, cut tree rooted at x and meld into root list.• To keep trees flat: as soon as a node has its second child
cut, cut it off and meld into root list (and unmark it).
![Page 35: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/35.jpg)
35
Cont..
Case 1. [heap order not violated]– Decrease key of x.– Change heap min pointer (if necessary).
![Page 36: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/36.jpg)
36
Cont..Case 2a. [heap order violated]– Decrease key of x.
![Page 37: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/37.jpg)
37
Cont..
Cut tree rooted at x, meld into root list, and unmark.
![Page 38: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/38.jpg)
38
Cont..
If parent p of x is unmarked (hasn't yet lost a child), mark it.
![Page 39: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/39.jpg)
39
Cont..
Case 2b. [heap order violated]– Decrease key of x.
![Page 40: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/40.jpg)
40
Cont..
Cut tree rooted at x, meld into root list, and unmark.
![Page 41: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/41.jpg)
41
Cont..
If parent p of x is marked
![Page 42: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/42.jpg)
42
Cont..
Cut p, meld into root list, and unmark
![Page 43: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/43.jpg)
43
Cont..
Do so recursively for all ancestors that lose a second child.
![Page 44: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/44.jpg)
44
Cont..
Do so recursively for all ancestors that lose a second child.
![Page 45: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/45.jpg)
45
Decrease key: Algorithm
![Page 46: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/46.jpg)
46
Cont..
![Page 47: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/47.jpg)
47
Decrease Key AnalysisDecrease-key.
Actual cost. O(c)– O(1) time for changing the key.– O(1) time for each of c cuts, plus melding into root list.
Change in potential. O(1) - c– trees(H') = trees(H) + c.– marks(H') marks(H) - c + 2.– c + 2 (-c + 2) = 4 - c.
Amortized cost. O(1)
(H) = trees(H) + 2 marks(H)Potential function
![Page 48: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/48.jpg)
48
Delete
Delete node x.– decrease-key of x to -.– delete-min element in heap.
Amortized cost. O(rank(H))– O(1) amortized for decrease-key.– O(rank(H)) amortized for delete-min.
![Page 49: Fibonacci Heaps](https://reader036.fdocuments.fr/reader036/viewer/2022062901/58f0c6e91a28abc05f8b4695/html5/thumbnails/49.jpg)
49
THANK YOU