Fibonacci Heaps Group: N = NP Leader: T ang Hao Member: Chen Zhiqin Liao Mingding Shen Bingyu
Introduction • Binominal Heap • Fibonacci Heap – a better amortized running time than a binomial heap – developed by Michael L. Fredman and Robert E. Tarjan in 1984 – first published in a scientific journal in 1987 – The name of Fibonacci heap comes from Fibonacci numbers whic h are used in the running time analysis
Introduction A faster implementation of Prim’s MST algorithm and Dijkstra’s Shortest Paths algorithm. Operation running using time times insert(v, h) O(1) |V| delete- O(log n) |V| min(h) decrease(v, O(1) m(edges) Using Fibonacci Heaps, the total running time of Dij Δ) kstra or Prim is O(m + n log n)
Binomial Trees Binomial Trees are defined inductively.
Binomial Trees(cont.) Proposition 1 Two trees Bk can be merged into one Bk+1 in constant time. We call this the merg e operation. Proof. Proposition 2 A Bk tree contains exactly 2k nodes. Proof.
Binomial Heaps A collection of Binomial trees. For each rank k, at most one tree Bk is containe d. Each of the trees satisfy the heap property.
Binomial Heaps(cont.) Lemma 3 A Binomial Heap (over an n-element u niverse) contains at most O(log n) trees. Proof.
Comparisons Operation Bio. Heap Fib. Heap insert(v, h) O(log n) O(1) delete-min(h) O(log n) O(log n) decrease(v, O(log n) O(1) Δ) Our goal is to implement the insert operation in time O(1).
Insert
Delete_min
Delete_min.cont
Delete_min.cont
Delete_min.cont
Delete_min.cont
Delete_min.cont
Delete_min.cont
Delete_min.cont
Delete_min.cont
Delete_min.cont
Delete_min.cont
Delete_min.cont
Merge Credit 1 1 Credit Credit 1 + 1 – 1 = 1 Credit
Analysis Push off the meld operation from insert to delete_min. Merge credit: one unit operation to merge two trees together, it tak es O(1) time. Insert: each tree is given on merge credit. So the insert operation do es one insert operation and one merge credit. Delete_min: we first meld the trees together. When two trees merged to gether to one tree, we use one merge credit, and the result is one new tree with one merge credit. So meld is free. Delete_min only cost O(max deg) to search all the trees and O(deg(min)) to put its sons into the root list.
decrease add a decrease operation that runs in (amort ized) time O(1) -- decrease(v, Δ ).
Decrease.cont decrease 23 to 3
Decrease.cont Decrease 42 to 2
Decrease.cont
Decrease If we decrease the value for some node v: • Let p be the parent of v. • Delete v and its subtree and make them a new tree. • If the parent of v, p, has no other child been removed, then that’s all we do. • If p has already lost a child, we also remove p itself and its remaining subtree. • Consider p as a child of its parent p0, and do 3~5.
Cut Credit
Cut Credit Cut this node !
Cut Credit 1 merge credit 1 cut credit 1 merge credit
Cut Credit 1 merge credit 1 cut credit 1 merge credit
Cut Credit 1 merge credit 1 merge credit 2 cut credit 2 merge credit
Cut Credit 1 merge credit 1 merge credit 2 cut credit 2 merge credit
Cut Credit 1 merge credit 1 merge credit 1 merge credit 1 cut credit 1 merge credit
Analysis Cut credit: one unit operation to cut one subtree, it takes O (1) time. decrease: the decrease function cuts the subtree, give the n ew tree one merge credit and give the parent of the node one merge credit and one cut credit. It takes O(1) time. Iteration cut: if the nodes has lost two children, it will contain two merge credits and two cut credits. Use one cut credit to cut the subtree, give one merge credit to the new tree, give o ne merge credit and one cut credit to the parent of it. Then t he iteration cut is free.
Size of a tree in a Fib Heap Proof.
Analysis Sk: The smallest number of nodes that could be in a t ree of rank k. Sk = 1 + S0 + S0 + S1 + S2 + . . . + Sk 3 + Sk 2 − − Sk 1 = 1 + S0 + S0 + S1 + S2 + . . . + Sk 4 + Sk 3 − − − Sk Sk 1 = Sk 2 − − − Fibonacci numbers
Analysis Proof.
Worst Case of Heap Size S 3 S S 2 1 1 S S 0 0 S 4
Conclusion After the clean-up operation, the delete_min operati on only needs to check O(log n) roots, and hence t erminates in O(log n) steps. the operations in Prim’s or Dijkstra’s algorithm take time O(m + n + n log n) = O(m + n log n).
References 1. https://en.wikipedia.org/wiki/Fibonacci_heap https://en.wikipedia.org/wiki/Binomial_heap 2. Thomas H.; Leiserson, Charles E., Rivest, Ronald L. (1990). Introduction to Algorith 3. ms (1st ed.). MIT Press and McGraw-Hill. ISBN 0-262-03141-8. http://www.cnblogs.com/skywang12345/p/3659060.html 4. http://www-bcf.usc.edu/~dkempe/teaching/fibonacci.pdf 5.
Recommend
More recommend