Isomorphism of Grphs Definition The simple grphs G 1 = (V 1, E 1 ) n G = (V, E ) re isomorphi if there is ijetion (n oneto-one n onto funtion) f from V 1 to V with the property tht n re jent in G 1 if n only if f() n f() re jent in G, for ll n in V 1. Suh funtion f is lle n isomorphism. In other wors, G 1 n G re isomorphi if their verties n e orere in suh wy tht the jeny mtries M G1 n M G re ientil. Isomorphism of Grphs From visul stnpoint, G 1 n G re isomorphi if they n e rrnge in suh wy tht their isplys re ientil (of ourse without hnging jeny). Unfortuntely, for two simple grphs, eh with n verties, there re n! possile isomorphisms tht we hve to hek in orer to show tht these grphs re isomorphi. However, showing tht two grphs re not isomorphi n e esy. Nov 1 CS 3 1 Nov 1 CS 3 Isomorphism of Grphs For this purpose we n hek invrints, tht is, properties tht two isomorphi simple grphs must oth hve. For exmple, they must hve the sme numer of verties, the sme numer of eges, n the sme egrees of verties. Note tht two grphs tht iffer in ny of these invrints re not isomorphi, ut two grphs tht mth in ll of them re not neessrily isomorphi. Nov 1 CS 3 3 Isomorphism of Grphs I Are the following two grphs isomorphi? e e Solution Yes, they re isomorphi, euse they n e rrnge to look ientil. You n see this if in the right grph you move vertex to the left of the ege {, }. Then the isomorphism f from the left to the right grph is f() = e, f() =, f() =, f() =, f(e) =. Nov 1 CS 3 Isomorphism of Grphs II How out these two grphs? e Solution No, they re not isomorphi, euse they iffer in the egrees of their verties. Vertex in right grph is of egree one, ut there is no suh vertex in the left grph. Nov 1 CS 3 e Counting Pths Between Verties Theorem (p. 88, p. 8 th e.). Suppose G is grph with verties {v 1,v,,v n } n A is the nxn jeny mtrix of G. G n e irete or unirete n multiple eges n loops re llowe. Then the (i,j) th entry of A r is the numer of ifferent pths of length r from v i to v j. Nov 1 CS 3 1
Proof We use inution on r, pth length. Bse Cse r=1. True y efinition of the jeny mtrix A = A 1. A ij = the numer of eges from v i to v j. Inution Step. Suppose true for r-1. (A r ) ij = k=1n (A r-1 ) ik * A kj. Eh term of the sum represents the numer of pths of length r-1 from v i to v k, multiplie y the numer of eges from v k to v j. The sum of these over k is extly the numer of pths of length r from v i to v j. Counting pths etween verties Rell we hve seen this theorem efore, when we were looking t trnsitive losures of reltions, t lest for the se of grphs without multiple eges. Nov 1 CS 3 7 Nov 1 CS 3 8 Use the jeny mtrix A G for the following grph G se on the orer of verties,,,, to ompute pths of vrious lengths in the grph. There re no pths of length > 3. Shortest Pth Prolems We n ssign weights to the eges of grphs, for exmple to represent the istne etween ities in rilwy network Chigo 7 Toronto Boston New York Nov 1 CS 3 9 Nov 1 CS 3 1 Shortest Pth Prolems Suh weighte grphs n lso e use to moel omputer networks with response times or osts s weights. One of the most interesting questions tht we n investigte with suh grphs is Wht is the shortest pth etween two verties in the grph, tht is, the pth with the miniml sum of weights long the wy? This orrespons to the shortest trin onnetion or the fstest onnetion in omputer network. Dijkstr s lgorithm is n itertive proeure tht fins the shortest pth etween two verties n in weighte grph. It proees y fining the length of the shortest pth from to suessive verties n ing these verties to istinguishe set of verties S. The lgorithm termintes one it rehes the vertex. Nov 1 CS 3 11 Nov 1 CS 3 1
proeure Dijkstr(G weighte onnete simple grph with verties = v, v 1,, v n = n positive weights w(v i, v j ), where w(v i, v j ) = if {v i, v j } is not n ege in G) for i = 1 to n L(v i ) = L() = S = {the lels re now initilie so tht the lel of is ero n ll other lels re, n the istinguishe set of verties S is empty} while S egin u = vertex not in S with miniml L(u) S = S {u} for ll verties v not in S if L(u) + w(u, v) < L(v) then L(v) = L(u) + w(u, v) {this s vertex to S with miniml lel n uptes the lels of verties not in S} en {L() = length of shortest pth from to } Nov 1 CS 3 13 Nov 1 CS 3 1 () 1 8 3 1 e Step Nov 1 CS 3 1 1 8 3 1 () e Step 1 Nov 1 CS 3 1 3 (, () ) 1 (, ) 3 (, () ) 1 8 (,, ) ) 1 8 3 1 () e 1 (, ) Step Nov 1 CS 3 17 1 8 3 1 () e 1 (, ) Step 3 Nov 1 CS 3 18 3
3 (, () ) 1 8 (,, ) ) 3 (, () ) 1 8 (,, ) ) 1 8 3 Step 1 (,,, ) 1 () e 1 1 (, ),, ) Nov 1 CS 3 19 1 8 3 13 1 (, (,,,,,, ) e) 1 () e 1 1 (, ),, ) Step Nov 1 CS 3 Step 1 3 (, () ) 1 8 (,, ) ) () 8 1 1 13 (, (,,,,,, ) e) e 1 1 (, ),, ) Nov 1 CS 3 1 3 Theorem Dijkstr s lgorithm fins the length of shortest pth etween two verties in onnete simple unirete weighte grph. Theorem Dijkstr s lgorithm uses O(n ) opertions (itions n omprisons) to fin the length of the shortest pth etween two verties in onnete simple unirete weighte grph. Plese tke look t pges 79 to 71 ( th e. 1 to 3) for the ook s tretment of Dijkstr s lgorithm. Nov 1 CS 3 Proof tht works proeure Dijkstr(G verties = v, v 1,, v n =, w(v i, v j )>, w(v i, v j ) = if {v i, v j } not n ege in G) for i = 1 to n {L(v i ) = ;L() = ;S = } // loop invrint v S, L(v) = length of shortest pth in G from to v, n u S, L(u) = length of shortest pth to u, suh tht ll verties in the pth exept u re in S. while S egin u = vertex not in S with miniml L(u) S = S {u} for ll verties v not in S if L(u) + w(u, v) < L(v) then L(v) = L(u) + w(u, v) en // n psses through the loop, t most n opertions eh. {L() = length of shortest pth from to } Nov 1 CS 3 3 Fining the shortest pth We n moify Dijkstr s lgorithm to fin not just the length of the shortest pth, ut the pth itself. For eh vertex v, keep list of the shortest pth so fr to v, s list of verties. Initilly L(v) = n the list is empty. Eh time we reset L(v) y L(v) = L(u) + w(u, v) we reset v s list to e u s list followe y v Nov 1 CS 3
The Trveling Slesmn Prolem The trveling slesmn prolem is one of the lssil prolems in omputer siene. A trveling slesmn wnts to visit numer of ities n then return to his strting point. Of ourse he wnts to sve time n energy, so he wnts to etermine the shortest pth for his trip. We n represent the ities n the istnes etween them y weighte, omplete, unirete grph. The prolem then is to fin the iruit of minimum totl weight tht visits eh vertex extly one. Nov 1 CS 3 The Trveling Slesmn Prolem Wht pth woul the trveling slesmn tke to visit the following ities? Chigo 7 Toronto 7 New York Boston Solution The shortest pth is Boston, New York, Chigo, Toronto, Boston (, miles). Nov 1 CS 3 The Trveling Slesmn Prolem Question Given n verties, how mny ifferent yles C n n we form y onneting these verties with eges? Solution We first hoose strting point. Then we hve (n 1) hoies for the seon vertex in the yle, (n ) for the thir one, n so on, so there re (n 1)! hoies for the whole yle. However, this numer inlues ientil yles tht were onstrute in opposite iretions. Therefore, the tul numer of ifferent yles C n is (n 1)!/. Nov 1 CS 3 7 The Trveling Slesmn Prolem Unfortuntely, no lgorithm solving the trveling slesmn prolem with polynomil worst-se time omplexity hs yet een evise. This mens tht for grphs with lrge numer of verties, solving the trveling slesmn prolem is imprtil. In these ses, we n use pproximtion lgorithms tht etermine pth whose length my e slightly lrger thn the trveling slesmn s pth, ut n e ompute with polynomil time omplexity. For exmple, rtifiil neurl networks n o suh n effiient pproximtion tsk. Nov 1 CS 3 8 The Kőnigserg rige prolem (se 1.) The town of Kőnigserg h seven riges onneting prts of the ity. People wonere if one oul wlk over the riges, rossing eh rige extly one. See http//mthforum.org/is/prolems/riges1.html The Kőnigserg rige prolem This prolem ws solve y the Swiss mthemtiin Euler in 173. Perhps his ws the first result in grph theory. Nov 1 CS 3 9 Nov 1 CS 3 3
Euler iruits & pths Def. An Euler iruit is simple iruit ontining every ege of the grph. ( simple mens it oes not ontin the sme ege twie). Def. An Euler pth is simple pth ontining every ege of the grph. (en vertex my iffer from strt vertex) Euler iruits Theorem 1 (p. 9, th e. p. 3) A onnete multigrph with t lest two verties hs n Euler iruit iff eh vertex hs even egree. Proof This is simple ut powerful result, n it s not hr to see why it s true Nov 1 CS 3 31 Nov 1 CS 3 3 If the grph hs n Euler iruit then eh time the iruit enters vertex there must e nother ege for it to leve. The exeption is the strt vertex. When the pth enters this vertex t the en of the iruit the mthing ege is the first ege on the pth. En of proof of Theorem 1, p 9 Conversely, if every vertex hs even egree, if we strt pth t n ritrry vertex n keep going s long s possile, seleting only unuse eges, we will hve to stop only when we get to the strt vertex. This is euse every vertex hs even egree, so if there is wy in, there is wy out. If we hve use every ege we re one. If we hve not use every ege, strt nother pth t the first vertex, u, on our route tht hs n unuse ege. If we keep going s long s possile we ll en t u. We n this new pth to our originl one, tking it the first time we visit u. Repeting this proess we ll onstrut iruit whih uses every ege in the grph extly one, n is thus n Euler iruit. Nov 1 CS 3 33 Nov 1 CS 3 3 Euler Pths Theorem (p. 97, th e. p. 37). A onnete multigrph hs n Euler pth ut not n Euler iruit iff it hs extly two verties of o egree. Note tht this theorem tells us tht the Kőnigserg rige prolem hs no solution. Proof of Th. Suppose we strt pth t one of the verties of o egree. If we one more ege, onneting oth verties of o egree then Th. 1 tells us we hve iruit. Removing this extr ege gives us n Euler pth. If we hve more thn two verties of o egree n oul onstrut n Euler pth we oul one extr ege n get n Euler iruit. But this woul ontrit Th. 1 sine we woul still hve verties of o egree. Nov 1 CS 3 3 Nov 1 CS 3 3