Intro to Grph Thory 04 IOI Cmp Rort Spnr Dmr, 0 Rort Spnr Intro to Grph Thory /0
Introution This is grph: 4 Rort Spnr Intro to Grph Thory /0
Introution This is not grph: x(x + )(x ) 4 0 - -4 - - -. - -0. 0 0.. Rort Spnr Intro to Grph Thory /0
Introution Dinition A grph is olltion o nos onnt y gs whih my or my not irt n/or wight Rort Spnr Intro to Grph Thory 4/0
Introution Dinition A grph is olltion o nos onnt y gs whih my or my not irt n/or wight Exmpls o grphs: A omputr ntwork (non-irt, non-wight) A ro mp (non-irt, wight) Winnrs in hss tournmnt (irt, non-wight) Pymnts in n onomy (wight, irt) Rort Spnr Intro to Grph Thory 4/0
Pths n Cyls Dinition A pth is squn o nos suh tht h lmnt is onnt y n g to th on or it. Rort Spnr Intro to Grph Thory /0
Pths n Cyls Dinition A pth is squn o nos suh tht h lmnt is onnt y n g to th on or it. A yl is pth with its lst lmnt qul to its irst. Rort Spnr Intro to Grph Thory /0
Pths n Cyls Dinition A pth is squn o nos suh tht h lmnt is onnt y n g to th on or it. A yl is pth with its lst lmnt qul to its irst. A onnt grph is on whih hs pth joining vry pir o vrtis. Rort Spnr Intro to Grph Thory /0
Pths n Cyls Dinition A pth is squn o nos suh tht h lmnt is onnt y n g to th on or it. A yl is pth with its lst lmnt qul to its irst. A onnt grph is on whih hs pth joining vry pir o vrtis. Cn you in pth n yl? 4 Rort Spnr Intro to Grph Thory /0
Pths n Cyls Dinition A pth is squn o nos suh tht h lmnt is onnt y n g to th on or it. A yl is pth with its lst lmnt qul to its irst. A onnt grph is on whih hs pth joining vry pir o vrtis. Cn you in pth n yl? 4 Exmpl Answr: Pth: --4- Cyl: 4----4 Rort Spnr Intro to Grph Thory /0
Trs Dinition A tr is n un-irt omplt grph with no yls. Rort Spnr Intro to Grph Thory /0
Trs Dinition A tr is n un-irt omplt grph with no yls. Exmpl 4 Rort Spnr Intro to Grph Thory /0
Trs Dinition A tr is n un-irt omplt grph with no yls. Exmpl 4 Thorm A tr o n vrtis hs n gs. Rort Spnr Intro to Grph Thory /0
Trs Dinition A tr is n un-irt omplt grph with no yls. Exmpl 4 Thorm A tr o n vrtis hs n gs. Proo. Inution. Strt with on vrtx, n susqunt ons. Rort Spnr Intro to Grph Thory /0
Trs Wights r pl on gs, n n rprsnt nything (lngths, osts, t.) 4 4 Rort Spnr Intro to Grph Thory /0
Grph Rprsnttions How o w rprsnt grph? Rort Spnr Intro to Grph Thory /0
Grph Rprsnttions How o w rprsnt grph? Lists o Nighours [(,),(,)] [(4,),(,4)] [(,),(4,)] [(,),(,),(,)] [(,4),(,)] [(,)] Mmory O(E) Rort Spnr Intro to Grph Thory /0
Grph Rprsnttions How o w rprsnt grph? Lists o Nighours [(,),(,)] [(4,),(,4)] [(,),(4,)] [(,),(,),(,)] [(,4),(,)] [(,)] Mmory O(E) Ajny Mtrix 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 Mmory O(N ) Rort Spnr Intro to Grph Thory /0
Trvrsl Somtims w wnt to visit ll th nos in grph in prtiulr orr. For xmpl to srh or pth/stintion 4 4 Rort Spnr Intro to Grph Thory /0
Trvrsl Somtims w wnt to visit ll th nos in grph in prtiulr orr. For xmpl to srh or pth/stintion 4 4 W my visit nos mor thn on, s thr my mor thn on pth. E.g. to gt rom to, w my visit 4 twi: --4- or --4-. Rort Spnr Intro to Grph Thory /0
Trvrsl Somtims w wnt to visit ll th nos in grph in prtiulr orr. For xmpl to srh or pth/stintion 4 4 W my visit nos mor thn on, s thr my mor thn on pth. E.g. to gt rom to, w my visit 4 twi: --4- or --4-. Otn this is us to in th shortst rout twn two or mor nos. Rort Spnr Intro to Grph Thory /0
Dpth First Srh Dpth First Srh (DFS) visits th nos s r s it n or ktrking (without visiting nos mor thn on). Smpl Grph: 4 Rort Spnr Intro to Grph Thory 0/0
Dpth First Srh Dpth First Srh (DFS) visits th nos s r s it n or ktrking (without visiting nos mor thn on). Smpl Grph: 4 Psuoo: DFS(urrNo, inlno) i urrno==inlno thn rturn suss st urrno visit orh nighour o urrno o i nighour not visit thn DFS(nighour,inlNo) unst urrno visit Rort Spnr Intro to Grph Thory 0/0
Dpth First Srh Dpth First Srh (DFS) visits th nos s r s it n or ktrking (without visiting nos mor thn on). Smpl Grph: 4 Psuoo: DFS(urrNo, inlno) i urrno==inlno thn rturn suss st urrno visit orh nighour o urrno o i nighour not visit thn DFS(nighour,inlNo) unst urrno visit Nos (strting rom ) will visit in this orr: Rort Spnr Intro to Grph Thory 0/0
Dpth First Srh Dpth First Srh (DFS) visits th nos s r s it n or ktrking (without visiting nos mor thn on). Smpl Grph: 4 Psuoo: DFS(urrNo, inlno) i urrno==inlno thn rturn suss st urrno visit orh nighour o urrno o i nighour not visit thn DFS(nighour,inlNo) unst urrno visit Nos (strting rom ) will visit in this orr: ------------- Rort Spnr Intro to Grph Thory 0/0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dpth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Brth First Srh Brth First Srh (DFS) visits th nos in prlll without ktrking. Smpl Grph: 4 4 Rort Spnr Intro to Grph Thory /0
Brth First Srh Brth First Srh (DFS) visits th nos in prlll without ktrking. Smpl Grph: 4 4 Psuoo: BFS(urrNo, inlno) urrno to quu whil quu not mpty o pop irst lmnt s urrno st urrno visit orh nighour o urrno o i nighour not visit nighour to quu Rort Spnr Intro to Grph Thory /0
Brth First Srh Brth First Srh (DFS) visits th nos in prlll without ktrking. Smpl Grph: 4 4 Psuoo: BFS(urrNo, inlno) urrno to quu whil quu not mpty o pop irst lmnt s urrno st urrno visit orh nighour o urrno o i nighour not visit nighour to quu Nos (strting rom ) will visit in this orr: Rort Spnr Intro to Grph Thory /0
Brth First Srh Brth First Srh (DFS) visits th nos in prlll without ktrking. Smpl Grph: 4 4 Psuoo: BFS(urrNo, inlno) urrno to quu whil quu not mpty o pop irst lmnt s urrno st urrno visit orh nighour o urrno o i nighour not visit nighour to quu Nos (strting rom ) will visit in this orr: ---4-- Rort Spnr Intro to Grph Thory /0
Brth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Brth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Brth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Brth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Brth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Brth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Brth First Srh Exmpl 4 Rort Spnr Intro to Grph Thory /0
Dijkstr s Algorithm Dijkstr s Algorithm ins th shortst istn rom on no to ll othrs. It is silly BFS with priority quu. Psuoo: st ll istns INF (0, strtno) to quu whil quu not mpty o urrdists,urrno = quu.pop istns[urrno] = urrdist or nighour,istn in jnt[urrno] o possnwdist = istns[urrno] + istn i istns[nighour] > possnwdist thn upt nighour to wight possnwdist in quu Rort Spnr Intro to Grph Thory 4/0
Dijkstr s Algorithm Dijkstr s Algorithm ins th shortst istn rom on no to ll othrs. It is silly BFS with priority quu. Psuoo: st ll istns INF (0, strtno) to quu whil quu not mpty o urrdists,urrno = quu.pop istns[urrno] = urrdist or nighour,istn in jnt[urrno] o possnwdist = istns[urrno] + istn i istns[nighour] > possnwdist thn upt nighour to wight possnwdist in quu Rort Spnr Intro to Grph Thory 4/0
Dijkstr Exmpl 0 g Quu: {(, 0)} Rort Spnr Intro to Grph Thory /0
Dijkstr Exmpl 0 g Quu: {(, ), (, )} Rort Spnr Intro to Grph Thory /0
Dijkstr Exmpl 0 Quu: {(, ), (, ), (, 0)} 0 g Rort Spnr Intro to Grph Thory /0
Dijkstr Exmpl 0 4 Quu: {(, ), (, 4), (, )} g Rort Spnr Intro to Grph Thory /0
Dijkstr Exmpl 0 Quu: {(, 4), (, ), (g, )} 4 g g Rort Spnr Intro to Grph Thory /0
Dijkstr Exmpl 0 Quu: {(, ), (g, )} 4 g g Rort Spnr Intro to Grph Thory /0
Dijkstr Exmpl 0 4 g g Quu: {(g, )} Rort Spnr Intro to Grph Thory /0
Dijkstr Exmpl 0 4 g g Quu: {} Rort Spnr Intro to Grph Thory /0
Minimum Spnning Tr Dinition A minimum spnning tr is sust o gs in wight unirt grph suh tht th gs orm tr ontining ll th nos, n th sum o th wights o th tr is miniml. g Rort Spnr Intro to Grph Thory /0
Minimum Spnning Tr Dinition A minimum spnning tr is sust o gs in wight unirt grph suh tht th gs orm tr ontining ll th nos, n th sum o th wights o th tr is miniml. g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Prim s Algorithm ins th minimum spnning tr rom givn grph. Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Prim s Algorithm ins th minimum spnning tr rom givn grph. Algorithm St ll vrtis to not in th tr xpt strting vrtx. Whil thr r vrtis not in th tr, th vrtx whih is onnt to th tr y th shortst g to th tr. Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Prim s Algorithm ins th minimum spnning tr rom givn grph. Algorithm St ll vrtis to not in th tr xpt strting vrtx. Whil thr r vrtis not in th tr, th vrtx whih is onnt to th tr y th shortst g to th tr. Thnil nots Kp priority quu o gs. Eh stp pull o n g, hk i it joins nw vrtx. I it os, ll th gs rom tht vrtx to th quu. Runs in O(E log V ) with inry hp s priority quu. Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Prim s Algorithm Exmpl g Rort Spnr Intro to Grph Thory /0
Kruskl s Algorithm Kruskl s Algorithm is th ul o Prim s. It lso ins th minimum spnning tr. Rort Spnr Intro to Grph Thory /0
Kruskl s Algorithm Kruskl s Algorithm is th ul o Prim s. It lso ins th minimum spnning tr. Algorithm: Consir h vrtx s tr, ontining no gs n just itsl. Whil w on t hv MST, onsir th smllst g not yt onsir. I it joins two irnt trs, inlu it in th MST. Rort Spnr Intro to Grph Thory /0
Kruskl s Algorithm Kruskl s Algorithm is th ul o Prim s. It lso ins th minimum spnning tr. Algorithm: Consir h vrtx s tr, ontining no gs n just itsl. Whil w on t hv MST, onsir th smllst g not yt onsir. I it joins two irnt trs, inlu it in th MST. Thnil Nots: Us union-in to hol th irnt trs. Complxity O(E log E) Rort Spnr Intro to Grph Thory /0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0
Kruskl s Algorithm Exmpl g Rort Spnr Intro to Grph Thory 0/0