# 4-FibonacciHeap.ppt - Fibonacci Heap 2 Binary...

• 30

This preview shows page 1 - 8 out of 30 pages.

Fibonacci Heap
2 Design And Analysis of Algorithms Varun Arora ITS Procedure Binary heap (worst- case) Binomial heap (worst-case) Fibonacci heap (amortized) MAKE-HEAP (1) (1) (1) INSERT (lg n) O(lg n) (1) MINIMUM (1) O(lg n) (1) EXTRACT-MIN (lg n) (lg n) O(lg n) UNION (n) O(lg n) (1) DECREASE- KEY (lg n) (lg n) (1) DELETE (lg n) (lg n) O(lg n)
3 Design And Analysis of Algorithms Varun Arora ITS Fibonacci Heaps: A collection of min-heap-ordered trees. trees: rooted but unordered, whereas Binomial trees are ordered. Each node x contains: » P[x] - points to its parent » child[x] - points to any one of its children, children of x are linked together in a circular doubly linked list » degree[x] - number of children in the child list of x » mark[x] - indicate whether node x has lost a child since the last time x was made the child of another node » min[H] - points to the root of the tree containing a minimum key » n[H] - number of nodes in H Note: newly created nodes are unmarked and a node x becomes unmarked whenever it becomes the child of another node.
4 Design And Analysis of Algorithms Varun Arora ITS Potential function: Roots are linked together using their left and right pointers in a circular, doubly linked list called the root list of Fib. Heap. The order of the trees within a root list is arbitrary. D(n): upper bound on the max degree of any node in an n-node Fibonacci heap Fibonacci heap # of trees in the rooted list of H # of marked nodes in H (H) = t(H) + 2m(H)
5 Design And Analysis of Algorithms Varun Arora ITS (a) 23 7 41 39 24 30 17 38 18 52 26 3 46 35 min [ H ] (b) 23 7 41 39 24 30 17 38 18 52 26 3 46 35 min [ H ]
6 Design And Analysis of Algorithms Varun Arora ITS Make-Fib-Heap(H ) n[H]=0 min[H]=nil return H From There are no trees in H therefore t(H)=0 , m(H)=0 so (H)=0 The amortized cost of Make-Fib-Heap is equal to its O(1) actual cost. (H) = t(H) + 2m(H)
7 Design And Analysis of Algorithms Varun Arora ITS Fib-Heap-Insert(H, x) { degree[x] 0 P[x] NIL child[x] NIL left[x] x right[x] x mark[x] FALSE concatenate the root list containing x with root list H if min[H] = NIL or key[x]<key[min[H]] min[H] x n[H] n[H]+1 } Note : algo does not attempt to consolidate the trees within the fib heap.