presentation about Fibonacci heaps and its operations
Size: 569.02 KB
Language: en
Added: Nov 06, 2015
Slides: 49 pages
Slide Content
Fibonacci Heaps 1 Created by: Naseeba P P
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. 2
Cont.. 3 Node Pointers - left [x] - right [x] - degree [x] - number of children in the child list of x - - mark [x]
Cont.. Add to root list; update min pointer (if necessary). Increment the total number of nodes in the Heap, n[H]. 6
Insert: Algorithm 7
Insert Analysis Actual cost. O(1) Change in potential. +1 Amortized cost. O(1) P otential of heap H (H) = trees(H) + 2 marks(H) 8
Union Combine two Fibonacci heaps 9
Cont.. 10
Union: Algorithm 11
Union Analysis Potential function Actual cost. O(1) Change in potential. Amortized cost. O(1) 12 ( H ) = trees ( H ) + 2 marks ( H )
Delete or Extract Min Delete minimum 13
Cont.. Meld its children into root list. Update minimum. 14
Cont.. Consolidate trees so that no two roots have same rank. 15
Cont.. current 16
Cont.. current 17
Cont.. current 18
Cont.. current 19
Cont.. current Link 23 into 17 20
Cont.. Link 17 into 7 21
Cont.. Link 24 into 7 22
Cont.. current 23
Cont.. current 24
Cont.. current 25
Cont.. current Link 41 into 18 26
Cont.. 27
Cont.. 28
Cont.. Stop 29
Delete Min: Algorithm 30
Cont.. 31
Cont.. 32
Delete Min Analysis Delete 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 33
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). 34
Cont.. Case 1. [heap order not violated] Decrease key of x. Change heap min pointer (if necessary). 35
Cont.. Case 2a. [heap order violated] Decrease key of x. 36
Cont.. Cut tree rooted at x, meld into root list, and unmark. 37
Cont.. If parent p of x is unmarked (hasn't yet lost a child), mark it. 38
Cont.. Case 2b. [heap order violated] Decrease key of x. 39
Cont.. Cut tree rooted at x, meld into root list, and unmark. 40
Cont.. If parent p of x is marked 41
Cont.. Cut p, meld into root list, and unmark 42
Cont.. Do so recursively for all ancestors that lose a second child. 43
Cont.. Do so recursively for all ancestors that lose a second child. 44
Decrease key: Algorithm 45
Cont.. 46
Decrease Key Analysis Decrease-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 47
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. 48