Chptr 9 Grphs Grphs r vry gnrl lss of ojt, us to formliz wi vrity of prtil prolms in omputr sin. In this hptr, w ll s th sis of (finit) unirt grphs, inluing grph isomorphism, onntivity, n grph oloring. 9.1 Grphs A grph onsists of st of nos V n st of gs E. W ll somtims rfr to th grph s pir of sts (V,E). Eh g in E joins two nos in V. Two nos onnt y n g r ll nighors or jnt. For xmpl, hr is grph in whih th nos r Illinois itis n th gs r ros joining thm: 100
CHAPTER 9. GRAPHS 101 Chigo Bloomington Urn Dnvill Springfil Dtur Agrphgntrvrsinothirtions, sinthisstrtxmpl, i.. th gs r unirt. Whn isussing rltions rlir, w us irt grphs, in whih h g h spifi irtion. Unlss w xpliitly stt othrwis, grph will lwys unirt. Conpts for unirt grphs xtn in strightforwr wys to irt grphs. Whn thr is only on g onnting two nos x n y, w n nm th g using th pir of nos. W oul ll th g xy or (sin orr osn t mttr) yx or {x, y}. So, in th grph ov, th Urn-Dnvill g onnts th no Urn n th no Dnvill. In som pplitions, w n grphs in whih two nos r onnt y multipl gs, i.. prlll gs with th sm npoints. For xmpl, th following grph shows wys to trvl mong four itis in th Sn Frniso By Ar. It hs thr gs from Sn Frniso to Okln, rprsnting iffrnt mos of trnsporttion. Whn multipl gs r prsnt, w typilly ll th gs rthr thn trying to nm gs y thir npoints. This igrm lso illustrts loop g whih onnts no to itslf.
CHAPTER 9. GRAPHS 102 tourist ruis Sn Frniso Rt 101 Plo Alto frry pln I-80 Rt 84 Okln I-880 Frmont A grph is ll simpl grph if it hs nithr multipl gs nor loop gs. Unlss w xpliitly stt othrwis, grph will lwys simpl grph. Also, w ll ssum tht it hs t lst on no n tht it hs only finit numr of gs n nos. Agin, most onpts xtn in rsonl wy to infinit n non-simpl grphs. 9.2 Dgrs Th gr ofnov, writtn g(v)is thnumr of gs whih hv v s n npoint. Slf-loops, if you r llowing thm, ount twi. For xmpl, in th following grph, hs gr 2, hs gr 6, hs gr 0, n so forth. f
CHAPTER 9. GRAPHS 103 Eh g ontriuts to two no grs. So th sum of th grs of ll th nos is twi th numr of gs. This is ll th Hnshking Thorm n n writtn s g(v) = 2 E v V This is slightly iffrnt vrsion of summtion nottion. W pik h no v in th st V, gt its gr, n its vlu into th sum. Sin V is finit, w oul lso hv givn nms to th nos v 1,...,v n n thn writtn n v k Vg(v) = 2 E k=1 Th vntg to th first, st-s, styl is tht it gnrlizs wll to situtions involving infinit sts. 9.3 Complt grphs Svrl spil typs of grphs r usful s xmpls. First, th omplt grph on n nos (shorthn nm K n ), is grph with n nos in whih vry no is onnt to vry othr no. K 5 is shown low. To lult th numr of gs in K n, think out th sitution from th prsptiv of th first no. It is onnt to n 1 othr nos. If w look t th son no, it s n 2 mor onntions. An so forth. So w hv n k=1 (n k) = n 1 k=0 k = n(n 1) gs. 2
CHAPTER 9. GRAPHS 104 9.4 Cyl grphs n whls Suppos tht w hv n nos nm v 1,...,v n, whr n 3. Thn th yl grph C n is th grph with ths nos n gs onnting v i to v i+1, plus n itionl g from v n to v 1. Tht is, th st of gs is: So C 5 looks lik E = {v 1 v 2, v 2 v 3,..., v n 1 v n, v n v 1 } C n hs n nos n lso n gs. Cyl grphs oftn our in ntworking pplitions. Thy oul lso us to mol gms lik tlphon whr popl sit in irl n ommunit only with thir nighors. Th whl W n is just lik th yl grph C n xpt tht it hs n itionl ntrl hu no whih is onnt to ll th othrs. Noti tht W n hs n+1 nos (not n nos). It hs 2n gs. For xmpl, W 5 looks lik hu
CHAPTER 9. GRAPHS 105 9.5 Isomorphism In grph thory, w only r out how nos n gs r onnt togthr. W on t r out how thy r rrng on th pg or in sp, how th nos n gs r nm, n whthr th gs r rwn s stright or urvy. W woul lik to trt grphs s intrhngl if thy hv th sm strt onntivity strutur. Spifilly, suppos tht G 1 = (V 1,E 1 ) n G 2 = (V 2,E 2 ) r grphs. An isomorphism from G 1 to G 2 is ijtion f : V 1 V 2 suh tht nos n r join y n g if n only if f() n f() r join y n g. Th grphs G 1 n G 2 r isomorphi if thr is n isomorphism from G 1 to G 2. For xmpl, th following two grphs r isomorphi. W n prov this y fining th funtion f so tht it mps 1 to, 2 to, 3 to, n 4 to. Th rr n thn vrify tht gs xist in th lft grph if n only if th orrsponing gs xist in th right grph. 1 3 2 4 Grph isomorphism is nothr xmpl of n quivln rltion. Eh quivln lss ontins group of grphs whih r suprfiilly iffrnt (.g. iffrnt nms for th nos, rwn iffrntly on th pg) ut ll rprsnt th sm unrlying strt grph. To prov tht two grphs r not isomorphi, w oul wlk through ll possil funtions mpping th nos of on to th nos of th othr. Howvr, tht s hug numr of funtions for grphs of ny intrsting siz. An xponntil numr, in ft. Inst, ttr thniqu for mny xmpls is to noti tht numr of grph proprtis r invrint, i.. prsrv y isomorphism. Th two grphs must hv th sm numr of nos n th sm numr of gs.
CHAPTER 9. GRAPHS 106 For ny no gr k, th two grphs must hv th sm numr of nos of gr k. For xmpl, thy must hv th sm numr of nos with gr 3. W n prov tht two grphs r not isomorphi y giving on xmpl of proprty tht is suppos to invrint ut, in ft, iffrs twn th two grphs. For xmpl, in th following pitur, th lfthn grph hs no of gr 3, ut th righthn grph hs no nos of gr 3, so thy n t isomorphi. 1 3 2 4 9.6 Sugrphs It s not hr to fin pir of grphs tht rn t isomorphi ut whr th most ovious proprtis (.g. no grs) mth. To prov tht suh pir isn t isomorphi, it s oftn hlpful to fous on rtin spifi lol fturs of on grph tht rn t prsnt in th othr grph. For xmpl, th following two grphs hv th sm no grs: on no of gr 1, thr of gr 2, on of gr 3. Howvr, littl xprimnttion suggsts thy rn t isomorphi. 1 3 2 4 5 To mk onvining rgumnt tht ths grphs rn t isomorphi, w n to fin th notion of sugrph. If G n G r grphs, thn G is sugrph of G if n only if th nos of G r sust of th nos of
CHAPTER 9. GRAPHS 107 G n th gs of G r sust of th gs of G. If two grphs G n F r isomorphi, thn ny sugrph of G must hv mthing sugrph somwhr in F. A grph hs hug numr of sugrphs. Howvr, w n usully fin vin of non-isomorphism y looking t smll sugrphs. For xmpl, in thgrphsov, thlfthngrphhsc 3 ssugrph, utthrighthn grph os not. So thy n t isomorphi. 9.7 Wlks, pths, n yls In grph G, wlk of lngth k from no to no is finit squn of nos = v 1,v 2,...,v n = n finit squn of gs 1, 2,..., n 1 in whih i onnts v i n v i+1, for ll i. Unr most irumstns, it isn t nssry to giv oth th squn of nos n th squn of gs: on of th two is usully suffiint. Th lngth of wlk is th numr of gs in it. Th shortst wlks onsist of just singl no n hv lngth zro. A wlk is los if its strting n ning nos r th sm. Othrwis it is opn. A pth is wlk in whih no no is us mor thn on. A yl is los wlk with t lst thr nos in whih no no is us mor thn on xpt tht th strting n ning nos r th sm. For xmpl, in th following grph, thr is lngth-3 wlk from to :,,. Anothr wlk of lngth 3 woul hv gs:,,. Ths two wlks r lso pths. Thr r lso longr wlks from to, whih rn t pths us thy r-us nos,.g. th wlk with no squn,,,,,.
CHAPTER 9. GRAPHS 108 In th following grph, on yl of lngth 4 hs gs:,,,. Othr losly-rlt yls go through th sm nos ut with iffrnt strting point or in th opposit irtion,.g.,,,. Unlik yls, los wlks n r-us nos,.g.,,,,, is los wlk ut not yl. f Th following grph is yli, i.. it osn t ontin ny yls. f Noti tht th yl grph C n ontins 2n iffrnt yls. For xmpl, ifthvrtisofc 4 rlllsshownlow, thnonylis,,,, nothr is,,,, n so forth.
CHAPTER 9. GRAPHS 109 9.8 Conntivity A grph G is onnt if thr is wlk twn vry pir of nos in G. Our prvious xmpls of grphs wr onnt. Th following grph is not onnt, us thr is no wlk from (for xmpl), to g. g f h If w hv grph G tht might or might not onnt, w n ivi G into onnt omponnts. Eh onnt omponnt ontins mximl (i.. iggst possil) st of nos tht r ll onnt to on nothr, plus ll thir gs. So, th ov grph hs thr onnt omponnts: on ontining nos,,, n, son ontining nos, f, n g, n thir tht ontins only th no h. Somtims two prts of grph r onnt y only singl g, so tht th grph woul om isonnt if tht g wr rmov. This is ll ut g. For xmpl, in th following grph, th g is ut g. In som pplitions, ut gs r prolm. E.g. in ntworking, thy r pls whr th ntwork is vulnrl. In othr pplitions (.g. ompilrs), thy rprsnt opportunitis to ivi lrgr prolm into svrl simplr ons. g f
CHAPTER 9. GRAPHS 110 9.9 Distns In grphs, istns r s on th lngths of pths onnting pirs of nos. Spifilly, th istn (,) twn two nos n is th lngth of th shortst pth from to. Th imtr of grph is th mximum istn twn ny pir of nos in th grph. For xmpl, th lfthn grph low hs imtr 4, us (f,) = 4 n no othr pir of nos is furthr prt. Th righthn grph hs imtr 2, us (1,5) = 2 n no othr pir of nos is furthr prt. f 1 3 5 2 4 9.10 Eulr iruits An Eulr iruit of grph G is los wlk tht uss h g of th grph xtly on. For xmpl, on Eulr iruit of th following grph woul,, f, f,, f, f,. f An Eulr iruit is possil xtly whn th grph is onnt n h no hs vn gr. Eh no hs to hv vn gr us, in orr to omplt th iruit, you hv to lv h no tht you ntr. If th
CHAPTER 9. GRAPHS 111 no hs o gr, you will vntully ntr no ut hv no unus g to go out on. Fsintion with Eulr iruits ts k to th 18th ntury. At tht tim, th ity of Königrg, in Prussi, h st of rigs tht look roughly s follows: Folks in th town wonr whthr it ws possil to tk wlk in whih you ross h rig xtly on, oming k to th sm pl you strt. This is th kin of thing tht strts long ts lt t night in pus, or kps popl mus uring oring hurh srvis. Lonr Eulr ws th on who xplin lrly why this isn t possil. For our spifi xmpl, th orrsponing grph looks s follows. Sin ll of th nos hv o gr, thr s no possiility of n Eulr iruit. 9.11 Grph oloring A oloringof grph G ssigns olor to h no of G, with th rstrition tht two jnt nos nvr hv th sm olor. If G n olor with
CHAPTER 9. GRAPHS 112 k olors, w sy tht G is k-olorl. Th hromti numr of G, writtn χ(g), is th smllst numr of olors n to olor G. For xmpl, only thr olors r rquir for this grph: R G R G B But th omplt grph K n rquirs n olors, us h no is jnt to ll th othr nos. E.g. K 4 n olor s follows: R G B Y To stlish tht n is th hromti numr for grph G, w n to stlish two fts: χ(g) n: G n olor with n olors. χ(g) n: G nnot olor with lss thn n olors For smll finit grphs, th simplst wy to show tht χ(g) n is to show oloring of G tht uss n olors. Showing tht χ(g) n n somtims qully strightforwr. For xmpl, G my ontin opy of K n, whih n t olor with lss thn n olors. Howvr, somtims it my nssry to stp rfully through ll th possil wys to olor G with n 1 olors n show tht non of thm works out.
CHAPTER 9. GRAPHS 113 So trmining th hromti numr of grph n rltivly sy for grphs with hlpful strutur, ut quit iffiult for othr sorts of grphs. A fully gnrl lgorithm to fin hromti numr will tk tim roughly xponntil inthsizofthgrph, forthmostiffiult input grphs. 1 Suh slow running tim isn t prtil xpt for smll xmpls, so pplitions tn to fous on pproximt solutions. 9.12 Why shoul I r? Grph oloring is rquir for solving wi rng of prtil prolms. For xmpl, thr is oloring lgorithm m in most ompilrs. Bus th gnrl prolm n t solv ffiintly, th implmnt lgorithms us limittions or pproximtions of vrious sorts so tht thy n run in rsonl mount of tim. For xmpl, suppos tht w wnt to llot rost frqunis to lol rio sttions. In th orrsponing grph prolm, h sttion is no n th frqunis r th olors. Two sttions r onnt y n g if thy r gogrphilly too los togthr, so tht thy woul intrfr if thy us th sm frquny. This grph shoul not too to olor in prti, so long s w hv lrg nough supply of frqunis ompr to th numrs of sttions lustr nr on nothr. W n mol suoku puzzl y stting up on no for h squr. Th olors r th 9 numrs, n som r pr-ssign to rtin nos. Two nos r onnt if thir squrs r in th sm lok or row or olumn. Th puzzl is solvl if w n 9-olor this grph, rspting th pr-ssign olors. W n mol xm shuling s oloring prolm. Th xms for two ourss shoul not put t th sm tim if thr is stunt who is in othourss. So w n mol this s grph, in whih h ours is no n ourss r onnt y gs if thy shr stunts. Th qustion is thn whthr w n olor th grph with k olors, whr k is th numr of xm tims in our shul. In th xm shuling prolm, w tully xpt th nswr to 1 In CS thory jrgon, this prolm is HP-hr.
CHAPTER 9. GRAPHS 114 no, us liminting onflits woul rquir n xssiv numr of xm tims. So th rl prtil prolm is: how fw stunts o w hv to tk out of th pitur (i.. giv spil onflit xms to) in orr to l to solv th oloring prolm with rsonl vlu for k. W lso hv th option of splitting ours (i.. offring shul onflit xm) to simplify th grph. A prtiulrly importnt us of oloring in omputr sin is rgistr llotion. A lrg jv or C progrm ontins mny nm vrils. But omputr hs smllish numr (.g. 32) of fst rgistrs whih n f si oprtions suh s ition. So vrils must llot to spifi rgistrs. Th nos in this oloring prolm r vrils. Th olors r rgistrs. Two vrils r onnt y n g if thy r in us t th sm tim n, thrfor, nnot shr rgistr. As with th xm shuling prolm, w tully xpt th rw oloring prolm to fil. Th ompilr thn uss so-ll spill oprtions to rk up th pnnis n rt grph w n olor with our limit numr of rgistrs. Th gol is to us s fw spills s possil. 9.13 Biprtit grphs Anothr spil typ of grph is iprtit grph. A grph G = (V,E) is iprtit if w n split V into two non-ovrlpping susts V 1 n V 2 suh tht vry g in G onnts n lmnt of V 1 with n lmnt of V 2. Tht is, no g onnts two nos from th sm prt of th ivision. Or, ltrntivly, grph is iprtit if n only if it is 2-olorl. For xmpl, th u grph is iprtit us w n olor it with two olors:
CHAPTER 9. GRAPHS 115 G R R G G R R G Biprtit grphs oftn ppr in mthing prolms, whr th two susts rprsnt iffrnt typs of ojts. For xmpl, on group of nos might stunts, th othr group of nos might workstuy jos, n th gs might init whih jos h stunt is intrst in. Th omplt iprtit grph K m,n is iprtit grph with m nos in V 1, n nos in V 2, n whih ontins ll possil gs tht r onsistnt with th finition of iprtit. Th igrm low shows prtil iprtit grph on st of 7 nos, s wll s th omplt iprtit grph K 3,2. Th omplt iprtit grph K m,n hs m+n nos n mn gs. 9.14 Vrition in trminology Although th or is of grph thory r quit stl, trminology vris lot n thr is hug rng of spiliz trminology for spifi typs of grphs. In prtiulr, nos r oftn ll vrtis Noti tht th singulr of this trm is vrtx (not vrti ). A omplt grph on som
CHAPTER 9. GRAPHS 116 st of vrtis is lso known s liqu. Wht w r lling wlk us to wily ll pth. Authors who still us this onvntion woul thn us th trm simpl pth to xlu rptition of vrtis. Trms for losly-rlt onpts,.g. yl, oftn hng s wll.