fheaps - n"i hmgto Unnemts mSt Lows Engineering...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ' n "i . hmgto Unnemts mSt Lows Engineering Fibonacci Heaps Jon Turner Computer Science & Engineering Washington University www.ar1.wustl.edu/~jst :1,- Washmgton UnwersuymStlouis Engineering Fibonacci Heaps - Collection of me/dab/e heaps >> meld operation combines two heaps >> each heap is identified by one of its members (its id) >> initially, all items form singleton heap >> good amortized running time - Heap operations >>findmin(h): return an item of minimum key in h >>insert(i,x,h): insert item i into heap h with key X oi must be a singleton heap >>de/ete(i,h): delete item ifrom h and return resulting heap’s id >>de/etemin(h): delete a min key item from h; return it and new id >>me/d(h1,h2): return id of heap formed by combining h1 and hz; operation destroys h1 and h2 >>decreasekey(A,i,h): decrease key of i in h by A; return new id :1,- Mshmgton UnlverSItymStlouls Engineering Structure of Fibonacci Heaps - Each F-heap is represented by a collection of heap- ordered trees >>each node has its item’s key, an integer rank and a mark bit 0 rank(i) equals the number of children off >>each node has pointers to its parent, its left and right siblings and one of its children >>the tree roots are linked together on a circular list >>heap is identified by a root node of minimum key key,rank E \X/ashington University in St. Louis Engineering Implementing F-Heap Operations - For meld, combine root lists; implement insert as meld >>new heap identified by item of minimum key; takes 0(1) time I For delete(i,h) >>perform a decreasekey at i, to make i the item with smallest key >>perform a deletemin to remove ifrom the heap >>restore original key value ofi >>time is just sum of times for de/etemin and decreasekey I For deletemin >> remove min key item from root list >>combine its list of children with root list >>find new min key node >>while doing this, combine trees with root nodes of equal rank until no two nodes in root list have same rank :1,- Washmgton UnwersuymStlouls Engineering I Deletemin combines trees with equal rank roots >>insert tree roots into an array, at E> i 3 position determined by their rank @ >>make one root a child of the other whenever there is a “collision” 0 note that root of new tree increases its rank I For decreasekey(A,i,h) >>subtract A from key(/) then cut edge joining i to its parent p >>make detached subtree a separate tree in heap >>if key(i)<key(h), i becomes the min node of heap >>ifp is not a tree root, and i is second child cut from p, since p became child of some other node, cut edge from p to its parent 0 apply this rule recursively to parent of p, then its parent,... 0 use mark bit to identify nodes that have lost a child >>increases number of trees, decreases number of marked nodes :1,- Mshmgton UniversuymSttoms Engineering Review Questions 1. Draw two F—heaps, each containing two trees of three nodes each. Show them as heap-ordered trees and label each node with a unique letter, its key value and its rank. Use an arrow to identify the minimum key item in each heap. Show the heap that results from melding the two heaps. . Perform a de/etemin on the heap that you get at the end of problem 1. Show the intermediate structure that you get before you start combining root nodes of equal rank. Then show the final result. Be sure to label each node, including its key and rank. . Take your heap from the end of problem 2 and do a decreaseKey operation on some node x that has at least one child and whose parent is not a tree root. You may assume that the parent of X does not have its mark bit set. Show the structure of the heap after this operation is finished. Be sure to label each node appropriately and to note any changes in the mark bits. $Wash1ngton UnwersuymStlouis Engineering Amortized Analysis I Objective is to bound total time for sequence of ops >>some individual ops may take more time than others >>expensive ops must be balanced by (earlier) inexpensive ops .To facilitate analysis, imagine we’re given credits for each operation >>one credit pays for one unit of computation >>credits not used to pay for a current op can be saved for later >>the credit allocation for each operation is its effective cost I Central question: “How many new credits needed for each op to ensure there are always enough on hand?” - Following credit invariant is key to analysis at all times, the number of credits on hand is equal to number of trees in all heaps, plus twice number of marked non-root nodes $Msh1ngton UnwersuymStLouis Engineering I Determine number of new credits needed per op to pay for the op and maintain validity of invariant >> findmin, insert and meld each take constant time and don’t affect invariant, so just one new credit for each op >> time for deletemin bounded by number of steps in second part 0 so, need one new credit per step plus one for every net new tree 0 details to come >> time for decreasekey bounded by number of cuts performed and each cascading cut involves a marked node I Detailed analysis of decreasekey >> let k=number of cuts made by decreasekey >> running time for decreasekey is O(k) >> number of trees increases by k >> number of marked non-root nodes decreases by k—2 >> so, the number of new credits needed is k+k-2(k—2)=4 >> so, cost of the decreasekey is 0(1) :1,- Washmgton UnwersuymStlouis Engineering Detailed Analysis of Deletemin I Detailed analysis of deletemin >> let k=rank of node removed in de/etemin 0 number of trees increases by k during first part of the op 0 number of marked non—root nodes does not change >> in second part, tree roots of equal rank are combined >> let p=# of times a tree root collides with another, let q=# of times a tree root is inserted with no collision 0 running time for deletemin is O(p+q) 0 number of trees decreases by p during the second part >> so, number of new credits needed to pay for the op and maintain credit invariant is (p+q)+(k-p)=k+q >> note that both k and q are bounded by the max rank, which we will show is O(log n) I So, O(s+tlog n) time for s findmin, meld or decreasekey ops plus t delete or deletemin ops :1,- Washmgton UniverSItymStLouis Engineering Bound on Ranks ILemma 1. Let X be any node and let y1,...,y, be children of X, in order of time in which they were linked to X (earliest to latest); then, rank(y,)zi-2 for all i Proof. Just before y,- was linked to X, X had at least i—1 children So at that time, rank(y,) and rank(x) were equal and 2i—1 Since y,- is still a child of X, its rank has been decremented at most once since it was linked, implying rank(y,)2i-2 l l Corollary 1. A node of rank k has 2Fk+22¢k descendants (including itself), where Fk is k-th Fibonacci number, defined by F0=O, F1=1, Fk=Fk_1+Fk_2 and ¢=(1+51/2)/2 Proof. Let 5k be min possible number of descendants of a node of rank k; clearly, 50:1, 51:2 and by Lemma 1, 5k 22+ZUS,-Sk_2 S, for k22; the Fibonacci numbers satisfy Fk+2=1+2,,5,sk F,- from which Sk 2Fk+2 follows by induction on k l Corollary implies that rank(x) is O(|og n) In — Engineering S 2. Let Pd(n) denote the running time of Prim’s algorithm using d-heaps, where the value of d is chosen dynamically to give the best overall running time. Let PF(n) denote the running time of 1- Assume that items a through ’77 With keys Prim’s algorithm, using Fibonacci heaps. Which of 3, 5, 2, 7, 4, 10, 8, 6, 3, 6, 1/ 2: 9 are the following statements is true? Justify your inserted in alphabetical order into a answers. Fibonacci heap. Show the heap following the insertions. Then do a deletemin and Pd is 0(PF) when m = 3n. show the resulting heap state. Data structure after insertions (single node trees linked in circular list /key,rank Pd is 0(PF) when m = n2/4. 633,0 035,0 (32,0 @7,0 @2,0 699,0 Data structure after deletemin (including ' [inking process), Pd IS 0(PF) when m = n (log n)2. Washington University in St. Louis This is true, since Pd = O(m (|og n)/|og(2+m/n)) = O(n log n) and PF = S'2(m+ n log n) = (2(n log n). This is true, since Pd = O(m (|og n)/log(2+m/n)) = 0(n 2) and PF = S'2(m+ n log n) = 52(n2). This is false, since Pd = s’2(m (|og n)/log(2+m/n)) G 3 2'2 = s2(n (|og n)3/log log n) and PF: O(m+ n log n) = 0(n (|og n)2) and Q. 7 0 42 n (log ")3/Iog |og n grows more quickly than n , 0 3,1 639,0 0 3'1 (log n)2 does. ' = 3/2 6’0 Pd IS 0(PF) when m n . This is true, since Pd = O(m (log n)//og(2+m/n)) = 0(n 3/2) and PF = s’2(m+ n log n) = 52(n3/2). 11 — Engineering Washington University in St. Louis 3. In the Fibonacci heaps data structure, a cut between a vertex u and its parent v causes a cascading cut at v if v has already lost a child since it last became a child of some other vertex. Suppose we change this, so that a cascading cut is done at v only if v has already lost two children. How does this change alter the lemma shown below (this lemma is from the analysis of the running time of Fibonacci heaps)? Explain your answer. Lemma. Let X be any node in an F-heap. Let yl, . . . ,y, be the children of x, in order of time in which they were linked to X (earliest to latest). Then, rank(y,) 2 i—2 for all i. The inequality in the lemma becomes rank(y,-) a i—3. Since y, had the same rank as x when it became a child ofx and x must have had at least i-1 children at that time, y, must have had rank of at least i-1 when it became a child ofx. Since it still is a child of x, it can have lost at most two children since that time, so its rank must be at least i-3. Let 5k be the smallest possible number of descendants that a node of rank k has, in our modified version of Fibonacci heaps. Give a recursive lower bound on 5k. That is, give an inequality of the form 5k 2 f (50,51, . . . , SH) where fis some function of the S,’s for i<k. Clear/y 50:1, 51:2 and 52:3. For k>2, we can use the modified lemma to conclude that SkZ3+SO+S,+...+Sk_3. Note that the difference between the bounds for 5,, and for SM is SH. Use this to give a lower bound on the smallest number of descendants that a node with rank 7 can have. From the above, we have $323+So=4, S42 4+51=6, $526+52=9, 5529+S3213, 57213+S4219. ...
View Full Document

This note was uploaded on 03/08/2012 for the course CSE 542 taught by Professor Jonturner during the Spring '12 term at Washington State University .

Page1 / 12

fheaps - n"i hmgto Unnemts mSt Lows Engineering...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online