D Sruure n Algorihm FR 6. Informik Sner, Telikeplli WS 03/04 hp://www.mpi-.mpg.e/~ner/oure/lg03/inex.hml Soluion o ignmen 3 Exerie Arirge i he ue of irepnie in urreny exhnge re o rnform one uni of urreny ino more hn one uni of he me urreny. For exmple, uppoe h U.S. ollr uy 0.7 Briih poun, Briih poun uy 9.5 Frenh frn, n Frenh frn uy 0.6 U.S. ollr. Then y onvering urrenie, rer n r wih U.S. ollr n uy 0.7 9.5 0.6 =.064 U.S. ollr, hu urning profi of 6.4 peren. Suppoe h we re given n urrenie,,..., n n n n le R of exhnge re, uh h one uni of urreny i uy R[i, j] uni of urreny j. () Give n effiien lgorihm o eermine wheher or no here exi equene of urrenie i, i,..., ik uh h R[i, i ] R[i, i 3 ] R[i k, i k ] R[i k, i ] >. Anlyze he running ime of your lgorihm. () Give n effiien lgorihm o prin ou uh equene if one exi. Anlyze he running ime of your lgorihm. Hin: k i= x i = e P k i= ln x i. Furhermore, k i= x i > iff / k i= x i <. Soluion: Thi prolem n e inerpree grph prolem: Eh urreny i noe n eh poiiliy of exhnge eween wo urrenie i n ege. The ege re weighe y he exhnge re. The queion i: Doe here exi yle in he grph, uh h he prou of he ege weigh i greer hn? Sine he known grph lgorihm re eigne o minimize he um of he ege weigh ine of mximizing heir prou, we ue he following f: x x x k > () x x x k < () ln( ) x x x k < ln() (3) ln( x ) + ln( x ) + + ln( x n ) < 0 (4) If he ege weigh x re reple y ln( x ), hen he prolem reue o fining negive yle. ) We n ue vrin of he Floy-Wrhll-Algorihm for eermining he exiene of negive yle: (oninue on he nex pge)
proeure hnegcy((v,e,) : WeigheGrph) : oolen n := r(v ) ine : Arry [0,...n][0,...n] of Rel // Fill up mrix wih eful vlue for i:=0 o n o for j:=0 o n o if (i, j) E hen ine[i][j]:=(i,j) ele ine[i][j]:=+oo // Loop ll noe for k:=0 o n o // Loop ll pir of noe for i:=0 o n o for j:=0 o n o // Cn noe k help in onruing he ph from i o j? if ine[i][j]>ine[i][k]+ine[k,j] hen ine[i][j] := ine[i][k]+ine[k][j] // Chek ou negive vlue poiion (i,i) for i:=0 o n o if ine[i][i] < 0 hen reurn rue reurn fle Thi lgorihm ue hree nee loop over n noe. Hene, i running ime i O(n 3 ). ) In orer o eermine he noe of he negive yle, he ove rouine h o e moifie uh h i memorize he hore ph: proeure negcy((v,e,) : WeigheGrph) : Li of Li of Noe n := r(v ) ine : Arry [0,...n][0,...n] of Rel // Thi rry ell where o go nex in orer o go from noe i o noe j nexnoe : Arry[0,...n ][0,...n ] of Noe // Fill up mrie wih eful vlue for i:=0 o n o for j:=0 o n o if (i, j) E hen ine[i][j]:=(i,j) nexnoe[i][j]:=j ele ine[i][j]:=+oo nexnoe[i][j]:=nil // Loop ll noe for k:=0 o n o // Loop ll pir of noe for i:=0 o n o for j:=0 o n o // Cn noe k help in onruing he ph from i o j? if ine[i][j] > ine[i][k]+ine[k,j] hen ine[i][j] := ine[i][k]+ine[k][j] nexnoe[i][j] := nexnoe[i][k]
// Conru reul reul : Li of Li of Noe := // Chek ou negive vlue poiion (i,i) for i:=0 o n o if ine[i][i]<0 hen negy : Li of Noe := < i > // Follow nexnoe unil i h een rehe gin runnoe := i repe runnoe := nexnoe[runnoe][i] negy.puhbk(runnoe) unil runnoe==i reul.puhfron(negy) reurn reul The running ime of hi lgorihm i ill O(n 3 ), eue he nexnoe-loop loop n ime mximum. Exerie Conier he grph G n he flow f given on he righ. () I f loking flow? () Give he reiul grph G f. 3/ / /0 4/ () Give he lyere ugrph L f of G f. () Fin n ugmening ph n give he reuling ugmene flow. Repe unil he flow i mximum. (e) Give ure (, )-u for he mximum flow. Soluion: () 3/ / /0 4/ Every ph from o mhe eiher he pern,,..., or he pern,,,...,, where he ege (, ) n he ege (, ) re ure. Hene, he flow f i loking eue on every ph from o one ege i ure. ()
() () ugmening ph:,,,,,, δ = reuling ugmene flow: /0 4/3 3/ (e) S = {, } Exerie 3 Whih of he following lim re rue n whih re fle. Juify your nwer y giving eiher (hor) proof or ounerexmple. () In ny mximum flow here re no yle h rry poiive flow. (A yle e,..., e k rrie poiive flow iff f(e ) > 0,..., f(e k ) > 0.) Soluion Fle. Counerexmple: () There lwy exi mximum flow wihou yle rrying poiive flow. Soluion True. Le f e mximum flow n le C e yle wih poiive flow. Le δ = min e C f(e). Reuing he flow of eh ege in C y δ minin he vlue of he flow n e he flow f(e) of le one of he ege e C o zero. () If ll ege in grph hve iin piie, here i unique mximum flow. Soluion Fle. Counerexmple: /0 4/0 3/ / 4/ 3/0 () In iree grph wih mo one ege eween eh pir of verie, if we reple eh iree ege y n uniree ege, he mximum flow vlue remin unhnge. Soluion Fle. Counerexmple: (e) If we muliply ll ege piie y poiive numer λ, he minimum u remin unhnge. Soluion True. The vlue of every u ge muliplie y λ. Thu, he relive orer of u oe no hnge.
(f) If we poiive numer λ o ll ege piie, he minimum u remin unhnge. Soluion Fle. Counerexmple: λ = / 5/5 4/3 3/3 (g) If we poiive numer λ o ll ege piie, he mximum flow inree y muliple of λ. Soluion Fle. In he exmple ove, he mximum flow hnge y 3.