CS 2 Advancd Data Structurs and Algorithms Final Exam Solutions Jonathan Turnr /8/20. (0 points) Suppos that r is a root of som tr in a Fionacci hap. Assum that just for a dltmin opration, r has no childrn and that aftr th dltmin r has 0 childrn. Lt C th st of childrn of r aftr th dlt and lt ranks(c) th st of rank valus for th nods in C (sinc this is a st, if svral nods in C hav th sam rank, thir rank valu appars just onc in ranks(c)). What is th largst valu in ranks(c) right aftr th dltmin? That is what is max ranks(c)? 9 What is th valu of ranks(c) right aftr th dltmin? 0 Assum that som tim latr r is still a tr root and has th sam st of childrn. What is th smallst possil valu for max ranks(c) at this point? 8 What is th smallst possil valu for ranks(c) at this point? Suppos som tim latr, r is still a tr root ut no longr has th sam st of childrn? Lt C its currnt st of childrn. What is th smallst possil valu for C? 0 - -
2. (0 points) Th diagram low shows an intrmdiat stat in th xcution of th roundroin algorithm. Th partition data structur P is just shown as a collction of susts. Th lftist haps ar shown as sts of dgs. Th tr dgs ar not shown xplicitly. a d k P: {a,f} {,c} {,h,j} {d,g,i,k,m} 2 h(a)={af,fc,a,ad} f 2 g m 2 h(c)={cf,c,ch,a,d,} c h 2 j i h()={h,j,,g,j,ch,jh,ij} h(d)={ad,d,dg,dk,g,gi,gk,ij,im,km} Which dgs ar in th partial MST that has n found so far? af, c, h, j, dg, gi, gk, im In th hap h(d), which dgs would considrd dltd y th round-roin algorithm? dg, dk, gi, gk, im, km Suppos that h() is th first itm on th list usd y th round-roin algorithm. What is th nxt dg addd to th tr? ch Show th stat of th partition data structur aftr th nxt dg is addd (you may just list th sts in th partition data structur). {a,f}, {,c,,h,j}, {d,g,i,k,m} - 2 -
. (0 points) Considr th partial solution to th maximum wightd matching prolm shown low. a g d 7 h f 7 k 8 c i j List all th augmnting paths in this graph and th wight of ach path. cag cihg 0 chij jihg 2 jfkdg 2 Which of ths paths would slctd nxt y Edmonds algorithm? chij Suppos that during th xcution of Edmond s algorithm on som othr graph, dgs {a,}, {,c} and {a,c} form an odd lossom with as a. In addition, th tr containing this lossom also includs dgs {x,a} and {y,c}. Which of ths fiv dgs ar in th matching? c, ax Which of ths dgs must quality dgs? all fiv Which of ths vrtics is th parnt of th lossom? y - -
. (0 points) This prolm is concrnd with Dinic s algorithm on unit graphs. Lt G a unit graph with,000 vrtics and 0,000 dgs. Lt nw phass start at tims T and T 2 with T <T 2. Suppos that at tim T, lvl(t)= and at T 2, lvl(t)=0 (whr t is th sink). If vrtx u has incoming and 0 outgoing dgs, what is th largst numr of tims that nxtdg(u) can incrmntd twn T and T 2? *=7 Suppos that at tim T 2 th valu of th flow is 2. What is th largst possil valu for th maximum flow? If R is rsidual graph for currnt flow f, f* f is a flow on R that can dcomposd into paths of lngth 0 or mor. So, ach path contains at last 9 intrmdiat vrtics, with ach vrtx apparing on no mor than on path. So (998/9) f* f and sinc f =2, f* is at most 0+2=. Approximatly, what is th maximum possil numr of phass aftr tim T 2? Th numr of phass is at most 2 (n 2) /2 =. Sinc 9 phass hav alrady occurrd, thr can no mor than mor. - -
. (0 points) Th diagram low shows an implmntation of a dynamic tr usd y Dinic s algorithm (what Tarjan calls th virtual tr ). Draw th corrsponding actual tr that is implmntd y th givn virtual tr. Show how th tr is dividd into paths (that is, th show th dashd dgs) and for ach vrtx show its actual costs. a 2, Δmin, Δcost t 00 0, t 0,98 d h 0 p,0 2,0 d,0 g 9,0 m,2 a g 9 z 0, s w 2,0 0,0 k c 2,0 h n 2,0 x, i,0,0 f 0,0,0 p 7 c n i m w f z 7 x s k What is th augmnting path in th flow graph? szwmnadt What is th rsidual capacity of th path? Which dgs ar rmovd from th dynamic trs data structur aftr flow is addd to th path? wm,, dt - -
. ( points). In la, w usd an xtnsion on th asic d-hap that supports an fficint addtokys opration. Thr is anothr way to implmnt a hap with an fficint addtokys opration using a slf-adjusting inary sarch tr with vrtx costs that ar rprsntd using th diffrntial rprsntation usd in th dynamic trs data structur. Assuming that th hap wr rprsntd in this way, dscri an fficint mthod to implmnt th mthod ky(x), which rturns th ky valu for nod x. Kp in mind that to mak this fficint, th tr must rstructurd in th usual way for slf-adjusting trs. You can assum that th undrlying rotation mthods updat th Δmin and Δky valus as ndd. splay(x); rturn Δmin(x) Dscri an fficint algorithm that implmnts th findmin opration on th hap. If Δcost(root)=0, rturn root. Othrwis, slct a child of root with Δmin=0. Continu down th tr through nods with Δmin=0. Stop at th first nod x with Δcost=0. Splay(x) and rturn x. Dscri an fficint algorithm for implmnting th mthod insrt(u,k,root) whr u is a nw nod, k is its ky valu and root is th currnt root of th tr. Hint: not that u can insrtd at any location in th tr. Mak u th nw tr root and lt right(u)=root, p(root)=u. Lt Δmin(u)=min(k, Δmin(root)), Δcost(u)=k Δmin(u) and Δmin(root)=Δmin(root) Δmin(u). - -
7. (0 points) Lt T a alancd inary sarch tr (aka rd-lack tr) containing a laf u with dpth(u)=0 and a laf v with dpth(v)=? What is th smallst possil rank for th root of T. What is th largst possil rank? Th smallst possil rank is 7, th largst is. Approximatly, what is th smallst possil numr of nods in T? Th largst? A nod with rank 7 must hav at last 2 7 =27 nods in its tr. A nod with rank 22 may hav at most 2 22 dscndants, or aout million. Show th tr that rsults from prforming th opration join(a,p,x) on th st of sarch trs shown low. Th numrs shown ar th ranks. Ky valus hav n omittd. Don t forgt to ralanc and show th final rank valus. a p x f g c f a c g h d h i d i p x - 7 -
8. (0 points) Th figur at right shows what Tarjan calls a virtual tr (that is, th undrlying implmntation of th dynamic trs data structur). Each triangl rprsnts on solid tr,, q and y ar laf nods in thir trs and th numrs in th triangls rprsnt th numr of nods in thos trs. (so, th tr containing p and q has 00 nods). Lal ach of th vrtics a,, p, q, x and y with its individual wight, total wight and rank. Suppos w do a splay at nod y in th sarch tr with root x. How many nw crdits do w nd to nsur that w can pay for th splay and maintain th crdit invariant? *( 0)+=9 0 a 8,800,9 200 0 2,2,9 p,20,9 00 q 2,2, 20 x 00 y,00,,,0 Suppos w do splays at th thr nods y, q and? How many nw crdits do w nd to nsur that w can pay for all th splay stps in ths splays and maintain th crdit invariant? *(9 0)+=0-8 -
9. (0 points). Suppos w apply th FIFO variant of th prflow-push algorithm to a graph with 00 vrtics and 00 dgs. Approximatly, what is th maximum numr of stps that rlal a vrtx? <2n 2 =20,000 Suppos u is a vrtx with 0 incidnt dgs. Approximatly, what is th maximum numr of tims that nxtdg(u) is advancd during th xcution of th algorithm? 0*(numr of tims u is rlald)<20n=2000 Suppos that at th start of som pass, th valu of th potntial function usd in th analysis is 7. Suppos that during this pass, vry stp concluds y adding flow to an dg without saturating it. What is th largst possil valu of th potntial function at th nd of th pass? Suppos that during som othr pass, th potntial function incrass from to 7. What is th smallst possil numr of ralancing stps that can occur during this pass? - 9 -