Rin Stion 9.6 Minimum Spnnin Trs Outlin Minimum Spnnin Trs Prim s Alorithm Kruskl s Alorithm Extr:Distriut Shortst-Pth Alorithms A Fil Shrin Prolm Sy unh o usrs wnt to istriut il monst thmslvs. Btwn h pir o usrs thr is ost o snin inormtion. How n w most iintly t th il to vry usr? A Kvin Bon Prolm Evryon knows tht vry tor is 6 rs rom Kvin Bon. Inst o tryin to minimiz th istn, wht i w sk how mny ilms r n so tht vry tor is onnt to vry othr tor. Spnnin Trs Cn think o h o ths prolms s prunin s o rph to rriv t tr. Evry onnt rph ontins tr stutur. (Proly mny irnt trs.) From inition: A tr is n yli rph. Rmov n rom vry yl in rph, n you hv tr. 1
Minimum Spnnin Trs A Spnnin Tr Input: A rph G=(V, E) with wihts w. Output: A st o s T E, suh tht G =(V, T) is tr n th sum o wihts in T is minimiz. 6 Altrntly: Rmov s muh wiht s possil whil still rminin onnt. A Minimum Spnnin Tr Rll Dijkstr s Alorithm 6 For h no, mintin st known shortst pth At h itrtion, no with lst vlu is t its tru minimum, so ix tht no n upt nihors. Prim s Alorithm Prim s lorithm xmpl For h no, mintin st known ost onntin tht no to tr. At h itrtion, no with lst ost n to tr. Thn upt nihors. 6 A B C D E F G known ost 2
Runtim Ext sm s Dijkstr s lorithm On itrtion or h vrtx, n h itrtion must in min ovr ll vrtis, so O( ). Also hv to upt osts so totl o. I w us hp to in th minimum, thn h o upts tks O( ), n h in tks O( ), so. Qustion Whih is ttr, hp or no hp? Kruskl s Alorithm Kruskl s lorithm xmpl I: W wnt smll wiht s tht on t orm yl. So strt with o smllst wiht n s o inrsin wiht tht on t us yl, until w hv onnt th rph. 6 Implmntin Kruskl s N to rptly t lst ost. Us? N to hk i two vrtis r lry in sm omponnt. Us? How o w know whn to stop? Kruskl s psuoo Kruskl s Min Spnnin Tr( G ): Buil hp H rom s Whil # tr s < N-1 (u, v) = ltmin( H ) I in(v)!= in(u) Mrk (u, v) s tr Union(v, u) 3
Runtim Loop oul xut tims, n hp oprtions tk. Fun Topi: Intrnt Routin Exprimnt: Opn ommn lin n typ trrout www.yhoo.om Sm s Dijkstr s with hp, ut muh str in prti. Why? How os your omputr know how to t to Yhoo s omputr? Th Intrnt Grph Computrs r nos, s r links. Wiht links y ltny, nwith, lo, onomi tors, t. Thn run Dijkstr s lorithm, n you ll know st rout to ll othr omputrs. Prolm? Solution: Link-Stt Evry omputr knows its nihors. Sn tht nihor inormtion to vry othr no. Flooin: Eh no sns riv pkts to ll nihors. Evntully ll nos rh. Exmpl Prolms with Link-Stt Prolms? 6
Anothr Solution: Distn Vtor Exmpl Inst o tryin to shr omplt ntwork topoloy, just tll nihors out routs. A no vrtiss th st known vlu o th shortst pth rom it to ll othr nos. 6 Distn Vtor: Comprison lss t snt Intuitivly sms riht tht you shouln t n mp o th whol ntwork But: n sily t inonsistnt viws o th ntwork, lin to vry hvior, lik ininit loops Distn vtor us or 20 yrs in Intrnt. Link-Stt ommon now. Sl Not us in smll ntworks, lik our mpus ntwork Not us ross kon provirs ntwork topoloy is orport srt! Morl Grphs lorithms hv: Vry rih thory Compllin pplitions in lmost vry omin o CS, n mny yon. 5