ECS110 Lecture Notes for Friday, December 1,1995

Professor Rogaway conducting

Lecture 25

Scribe of the day: Chiu Men Lau




Today: Finish Binomial Heaps, Fibonacci Heaps

Reading Assignment: 5.7, 10.1, 10.7, 10.8


Given a typical B-heap as follow: It's nodes have the following data members: |--------------------| | degree | |--------------------| | key | |--------------------| | data | |--------------------| | youngest | sibling | | child | | |--------------------| min / <-----5--------13--------2--------7-----> / / | \ | 7 30 18 16 17 / \ / 50 40 19 | 51 The deletion of the min element from its circular list as follow: 5 13 30 18 16 7 / / \ | | 7 50 40 19 17 | 51 Before forming the circular list of min tree roots, we repeatedly join together pairs of min trees that have the same degree. This min tree joining is done by making the min tree whose root has a larger key a subtree of the other. For our example, we may first join the min trees with roots 13 and 16, as following: 5 13 30 18 7 / | / \ | | 7 16 50 40 19 17 | 51 Second, we may join the min trees with roots 5 and 13 : 5 30 18 7 / \ / \ | | 13 7 50 40 19 17 | | 16 51 Third, we join the min trees with roots 5 and 30, 18 and 7 : 5 18 / | \ / \ 30 13 7 7 19 / \ | | 50 40 16 17 | 51 The min tree joining step is followed by a step in which the min tree roots are linked to form a circular list and the B-heap pointer to point to the min tree root with smallest key. min / <-----5---------18------> / | \ / \ 30 13 7 7 19 / \ | | 50 40 16 17 | 51
Fibonacci Heaps An example of decrease key as follow: min / <-----5--------13--------30-----18---16----> / / \ | 7 50 40 19 | 51 the reduction of 50 by 48 as follow: min / <-----5--------13---2-----30----18--16-----> / | | | 7 51 40 19 Another example as follow: min / <-----12-------------7-------18--16---> / | \ | 30 20 15 19 / \ | 50 40 25 | 51 the reduction of 40 by 35 as follow: min / <-----12----5--------7-----------18--16----> / | \ | 30 20 15 19 / | 50 25 | 51 <--- but, this is not a B-heap tree any more, so we need number of nodes in the tree is exponential in the degree. For this, we add the Boolean data member ChildCut to each node. The node is now as follow: |---------------------| | degree | |---------------------| | childCut | |---------------------| | parent | |---------------------| | key | |---------------------| | data | |---------------------| |left |child|right | |sibling| |sibling| |---------------------| decrease-key(V, theta) 1. decrease the key of V. 2. If V is the root: If the new key is < min, adjust the min, done. 3. If V is not a root. If decreasing the key caused a violution in the heap property, cut V off of its parent, add it(and its children) to the root list, adjust min, if necessary. delete(V) 1. If V=min, delete-min 2. Excise V //doubly link the children 3. Link its children into the root list. Cascading Cut - helps the heap to keep the property of its nodes being exponential in the degree -Set to TRUE for P(a node) when you cut away the first child of P(delete, or decrease-key). -Set to FALSE, when Q first became the child of some other node. -When you cut off a node Q, if its parent P has its ChildCut==1, cut P off of its parent. An example of cascading cut as follow: Nodes with ChildCut = TRUE are 6, 8, 10, 12. And a decrease of key 14 by 4. 2 10 12 10 |\ / \ | / \ 4 5 --> 16 15 18 30 11 |\ 6 60 /|\ 20 8 7 | --> 8 6 2 10 / \ / \ /| \ 20 7 4 5 30 12 11 | |\ 60 14 18 /\ 16 15 before after The ChildCut value of 4 becomes TRUE. All other ChildCut values are unchanged. Lemma: There exist a c such that the following is true. In a sequence of F-heap operations, n of which are insert, the maximal degree of any node in heap will be <= lg(base of c) n. Proof: in the text book p534. Analysis: Amortized Time Actual Time Change in Potential Function ------------------------------------------------------------------------------ | |insert O(1) |B-heap|combine O(1) F-heap| |delete-min O(lg n) 1+t0 <= 2(lg n)-t0 |----------------------------------------------------------------------- | decrease-key O(1) 1+C 1+C-2C | delete O(lg n) 1+C C-2C+lg(base of c) n ------------------------------------------------------------------------------ C = # of cascading cut t0 = # of trees before the consolidation tf = # of trees after the consolidation consolidation = t0 - tf Potential = # of trees + 2(# of non-root nodes with ChildCut == 1) Potential(s) = # of Trees in S