CSCI 104 Graph Representation and Traversals. Mark Redekopp David Kempe
|
|
- Clarence Nichols
- 5 years ago
- Views:
Transcription
1 1 CSCI 104 Grp Rprsnttion n Trvrsls Mrk Rkopp Dvi Kmp
2 2 Oriin o Grp Tory In 1736, Eulr solv t prolm known s t Svn Bris o Könisr. T ity o Könisr, Prussi on t Prl Rivr, inlu two lr islns onnt to otr n t minln y svn ris. T prolm is to i wtr it is possil to ollow pt tt rosss ri xtly on (n optionlly: rturns to t strtin point) ttp://n.wikipi.or/wiki/svn_bris_o_k%c3%b6nisr
3 3 Eulr s Anlysis Wnvr you ntr non-trminl lnmss y ri you must lv y notr Bus its non-trminl you n't sty on you rriv Tus vry non-trminl lnmss must touin n vn numr o ris So tt you n ntr on on ri n lv on notr Howvr, ll our o t ln msss in t oriinl prolm r tou y n o numr o ris (on is tou y 5 ris, n o t otr tr r tou y 3).
4 4 Explntion Usin Grp Tory In "rp-spk", Eulr sow tt t possiility o wlk trou rp, trvrsin xtly on, pns on t rs o t nos. Eulr wlk = strt/n t irnt vrtis Eulr yl = strt/n t sm vrtx T r o no is t numr o s touin it. Eulr's rumnt sows tt nssry onition or t wlk o t sir orm is tt t rp onnt n v xtly zro or two nos o o r. I tr r 2 nos o o r, w n orm n Eulr wlk so tt w will strt t on o t o-r vrtis n n t t otr Sin t rp orrsponin to istoril Könisr s our nos o o r, it nnot v n Eulrin pt.
5 GRAPH REPRESENTATIONS 5
6 6 Grp Nottion Grps is olltion o vrtis (or nos) n s tt onnt vrtis Lt V t st o vrtis Lt E t st o s Lt V or n rr to t numr o vrtis Lt E or m rr to t numr o s V V =n=8 E (,) (,) (,) (,) (,) (,) (,) (,) (,) (,) (,) E =m=11
7 7 Grps in t Rl Worl Soil ntworks Computr ntworks / Intrnt Pt plnnin Intrtion irms Bioinormtis
8 8 Bsi Grp Rprsnttion Cn simply stor s in list/rry Unsort Sort V V =n=8 E (,) (,) (,) (,) (,) (,) (,) (,) (,) (,) (,) E =m=11
9 9 Grp ADT Wt oprtions woul you wnt to prorm on rp? Vrtx() : Vrtx E(v1, v2) tajnis(v1) : List<Vrtis> Rturns ny vrtx wit n rom v1 to itsl rmovvrtx(v) rmove(v1, v2) Exists(v1, v2) : ool #inlu<iostrm> usin nmsp st; tmplt <typnm V, typnm E> lss Grp{ }; Prt or tmpltin t t ssoit wit vrtx n s V n E
10 List o Vrtis Ajny Lists 10 Mor Common Grp Rprsnttions Grps r rlly just list o lists List o vrtis vin tir own list o jnt vrtis Altrntivly, somtims rps r lso rprsnt wit n jny mtrix Entry t (i,j) = 1 i tr is n twn vrtx i n j, 0 otrwis,,,,,,,,,,,,,, Ajny Mtrix Rprsnttion
11 List o Vrtis Ajny Lists 11 Grp Rprsnttions Lt V = n = # o vrtis n E = m = # o s Ajny List Rprsnttion O( ) mmory stor Existn o n rquirs srin jny list Ajny Mtrix Rprsnttion O( ) stor Existn o n rquirs O( ) lookup,,,,,,,,,,,,,, Ajny Mtrix Rprsnttion
12 List o Vrtis Ajny Lists 12 Grp Rprsnttions Lt V = n = # o vrtis n E = m = # o s Ajny List Rprsnttion O( V + E ) mmory stor Existn o n rquirs srin jny list Din r to t numr o s inint on vrtx ( () = 2, () = 5, t. Ajny Mtrix Rprsnttion O( V 2 ) stor Existn o n rquirs O(1) lookup (.. mtrix[i][j] == 1 ),,,,,,,,,,,,,, Ajny Mtrix Rprsnttion
13 List o Vrtis Ajny Lists 13 Grp Rprsnttions Cn '' t to '' in two ops? Ajny List For nior o Sr tt nior's list or Ajny Mtrix Tk t ot prout o row & olumn,,,,,,,,,,,,,, Ajny Mtrix Rprsnttion
14 List o Vrtis Ajny Lists 14 Grp Rprsnttions Cn '' t to '' in two ops? Ajny List For nior o Sr tt nior's list or Ajny Mtrix Tk t ot prout o row & olumn,,,,,,,,,,,,,, Ajny Mtrix Rprsnttion
15 List o Vrtis Outoin Es Sour 15 Dirt vs. Unirt Grps In t prvious rps, s wr unirt (mnin s r 'iirtionl' or 'rlxiv') An (u,v) implis (v,u) In irt rps, links r uniirtionl An (u,v) os not imply (v,u) For E (u,v): t sour is u, trt is v For jny list orm, you my n 2 lists pr vrtx or ot prssors n sussors,,,, Trt Ajny Mtrix Rprsnttion
16 List o Vrtis Sour 16 Dirt vs. Unirt Grps In irt rp wit (u,v) w in Sussor(u) = v Prssor(v) = u Usin n jny list rprsnttion my wrrnt two lists prssors n sussors,,,, Sus,,,, Prs Trt Ajny Mtrix Rprsnttion
17 17 Timout: Rl-worl xmpl PAGERANK ALGORITHM
18 18 PRnk Consir t rp t t rit Ts oul wps wit links sown in t orrsponin irtion Ts oul niorin itis PRnk nrlly tris to nswr t qustion: I w lt un o popl rnomly "wlk" t rp, wt is t proility tt ty n up t rtin lotion (p, ity, t.) in t "sty-stt" W oul solv tis prolm trou Mont-Crlo simultion (similr to CS 103 Coin-lippin m ssinmnt) Simult lr numr o rnom wlkrs n ror wr on ns to uil up n nswr o t proilitis or vrtx But tr r mor iint wys o oin it
19 Trt=i Trt 19 PRnk Lt us writ out t jny mtrix or tis rp Now lt us mk wit vrsion y normlizin s on t out-r o no Ex. I you'r t no B w v n o oin to A or E From tis you oul writ systm o linr qutions (i.. wt r t ns you n up t vrtx I t t nxt tim stp, ivn you r t som vrtx J now pa = 0.5*pB pb = pc pc = pa + pd + 0.5*pE pd = 0.5*pE pe = 0.5*pB W lso know: pa + pb + pc + pd + pe = 1 Sour Ajny Mtrix Sour=j Wit Ajny Mtrix [Divi ( i,j )/r(j)]
20 Trt=i 20 Systm o Linr Equtions pa = 0.5*pB pb = pc pc = pa + pd + 0.5*pE pd = 0.5*pE pe = 0.5*pB PRnk W lso know: pa + pb + pc + pd + pe = 1 I you know somtin out linr lr, you know w n writ ts qutions in mtrix orm s linr systm Ax = y Sour=j Wit Ajny Mtrix [Divi y ( i,j )/r(j)] pa pa pa = 0.5PB pb pb pb = pc * pc * pc = pc = pa+pd+0.5*pe pd pd pd = 0.5*pE pe pe pe = 0.5*pB
21 Trt=i 21 PRnk But rmmr w wnt t sty stt solution T solution wr t proilitis on't n rom on stp to t nxt So w wnt solution to: Ap = p W n: Us linr systm solvr (Gussin limintion) Or w n just s t prolm wit som proilitis n tn just itrt until t solution sttls own Sour=j pa pa pb pb * pc = pc pd pd pe pe Wit Ajny Mtrix [Divi y ( i,j )/r(j)]
22 22 Itrtiv PRnk But rmmr w wnt t sty stt solution T solution wr t proilitis on't n rom on stp to t nxt So w wnt solution to: Ap = p W n: Us linr systm solvr (Gussin limintion) Or w n just s t prolm wit som proilitis n tn just itrt until t solution sttls own Stp 0 Sol. * = Stp 1 Sol Stp 29 Sol.?? *??? Stp 30 Sol = Stp 1 Sol. Stp 2 Sol * = Atul PRnk Solution rom solvin linr systm:
23 23 Aitionl Nots Wt i w n t rp n now D s no inomin links wt is its PRnk? 0 Most PR loritms proility tt somon just ntrs tt URL (i.. ntrs t rp t tt no) Usully in somtin ll t mpin tor, α (otn osn roun 0.85) Proility o rnomly strtin or jumpin somwr = 1-α So t tim stp t nxt PR vlu or no i is ivn s: Pr i = 1 α N + α σ j Pr(i) N is t totl numr o vrtis Usully run 30 or so upt stps Strt Pr(i) = 1/N Pr(j) OutD(j)
24 24 In W Sr Sttin Givn som sr kywors w oul in t ps tt v tt mtin kywors W otn xpn tt st o ps y inluin ll sussors n prssors o tos ps Inlu ll ps tt r witin rius o 1 o t ps tt tully v t kywor Now onsir tt st o ps n t surp tt it inus Run PRnk on tt surp Full WGrp P Hits (Contin kywor) Expn (Prs & Sus) Inu Surp to run PRnk
25 TREES 25
26 26 Tr Dinitions Prt 1 A 3-ry (trinry) tr Dinition: A onnt, yli (no yls) rp wit: A root no, r, tt s 0 or mor sutrs Extly on pt twn ny two nos In nrl: Nos v xtly on prnt (xpt or t root wi s non) n 0 or mor ilrn -ry tr Tr wr no s t most ilrn Binry tr = -ry Tr wit n=2 L Lt il root sutr silins prnt Rit il Anstor Dsnnt Trms: Prnt(i): No irtly ov no i Cil(i): No irtly low no i Silins: Cilrn o t sm prnt Root: Only no wit no prnt L: No wit 0 ilrn Hit: Lnt o lrst pt rom root to ny l Sutr(n): Tr root t no n Anstor(n): Any no on t pt rom n to t root Dsnnt(n): Any no in t sutr root t n
27 27 Tr Dinitions Prt 2 Tr it: mximum # o nos on pt rom root to ny l Full -ry tr, T, wr Evry vrtx s 0 or ilrn n ll l nos r t t sm lvl I it >1 n ot sutrs r ull inry trs o it, nil I it ==1, tn it is ull y inition Complt -ry tr E lvl is ill lt-to-rit n nw lvl is not strt until t prvious on is omplt Bln -ry tr Tr wr sutrs rom ny no ir in it y t most 1 Full Complt, ut not ull Full DAPS, 6 t E. Fiur 15-8 Complt
28 28 Tr Hit A ull inry tr o n nos s it, lo 2 (n + 1) Tis implis t minimum it o ny tr wit n nos is lo 2 (n + 1) T mximum it o tr wit n nos is, n 15 nos => it lo 2 (16) = 4 5 nos => it = 5
29 29 Tr Trvrsls A trvrsl itrts ovr ll nos o t tr Usully usin pt-irst, rursiv ppro Tr nrl trvrsl orrins Pr-orr [Pross root tn visit sutrs] In-orr [Visit lt sutr, pross root, visit rit sutr] Post-orr [Visit lt sutr, visit rit sutr, pross root] Prorr(TrNo* t) { i t == NULL rturn pross(t) // print vl. Prorr(t->lt) Prorr(t->rit) } Inorr(TrNo* t) { i t == NULL rturn Inorr(t->lt) pross(t) // print vl. Inorr(t->rit) } Postorr(TrNo* t) { i t == NULL rturn Postorr(t->lt) Postorr(t->rit) pross(t) // print vl. }
30 30 Arry-s n Link-s TREE IMPLEMENTATIONS
31 31 Arry-Bs Complt Binry Tr Binry tr tt is omplt (i.. only t lowst-lvl ontins mpty lotions n itms lt to rit) n stor nily in n rry (lt s sy it strts t inx 1 n inx 0 is mpty) Cn you in t mtmtil rltion or inin t inx o no i's prnt, lt, n rit il? Prnt(i) = Lt_il(i) = Rit_il(i) = m prnt(5) = Lt_il(5) = Rit_il(5) =
32 32 Arry-Bs Complt Binry Tr Binry tr tt is omplt (i.. only t lowst-lvl ontins mpty lotions n itms lt to rit) n stor nily in n rry (lt s sy it strts t inx 1 n inx 0 is mpty) Cn you in t mtmtil rltion or inin no i's prnt, lt, n rit il? Prnt(i) = i/2 Lt_il(i) = 2*i Rit_il(i) = 2*i m prnt(5) = 5/2 = 2 Lt_il(5) = 2*5 = 10 Rit_il(5) = 2*5+1 = Non-omplt inry trs rquir mu mor ookpin to stor in rrys usully link-s ppros r prrr
33 33 0-Bs Inxin Binry tr tt is omplt (i.. only t lowst-lvl ontins mpty lotions n itms lt to rit) n stor nily in n rry (lt s sy it strts t inx 1 n inx 0 is mpty) Cn you in t mtmtil rltion or inin t inx o no i's prnt, lt, n rit il? Prnt(i) = Lt_il(i) = Rit_il(i) = prnt(5) = Lt_il(5) = Rit_il(5) =
34 34 D-ry Arry-s Implmnttions Arrys n us to stor -ry omplt trs Ajust t ormuls riv or inry trs in prvious slis in trms o A 3-ry (trinry) tr
35 35 Link-Bs Appros Mu lik link list ut now wit two pointrs pr Itm Us NULL pointrs to init no il Dynmilly llot n r itms wn you /rmov tm #inlu<iostrm> usin nmsp st; tmplt <typnm T> strut BTItm { T vl; BTItm<T>* lt,rit; BTItm<T>* prnt; }; // Bin. Sr Tr tmplt <typnm T> lss BinTr { puli: BinTr(); ~BinTr(); voi (onst T& v);... privt: BTItm<T>* root_; }; BTItm<T> luprint: Itm<T>* lt Itm<T>* prnt T vl Itm<T>* rit lss LinkBST: 0x0 root_
36 36 A(5) A(6) A(7) Link-Bs Appros 1 lss LinkBST: 0x0 root_ 2 root_ 3 root_ 4 root_ 0x10 Lt Prnt vl rit
37 37 Link-Bs Appros A(5) A(6) A(7) 0x10 root_ vl 7 rit NULL Lt NULL 0x00 0x10 root_ vl 5 rit NULL Lt NULL lss LinkBST: 0x0 root_ 1 2 0x10 root_ vl 5 rit 0x20 Lt NULL vl 6 rit NULL Lt NULL 0x x10 0x10 prnt NULL prnt NULL prnt 0x10 vl 5 rit 0x20 Lt NULL vl 6 rit 0x00 Lt NULL 0x20 0x10 prnt NULL prnt 0x10 prnt 0x20
38 BREADTH-FIRST SEARCH 38
39 39 Brt-First Sr Givn rp wit vrtis, V, n s, E, n strtin vrtx tt w'll ll u 0 BFS strts t u ( in t irm to t lt) n ns-out lon t s to nrst niors, tn to tir niors n so on Gol: Fin sortst pts (.k.. minimum numr o ops or pt) rom t strt vrtx to vry otr vrtx Dpt 0:
40 40 Brt-First Sr Givn rp wit vrtis, V, n s, E, n strtin vrtx, u BFS strts t u ( in t irm to t lt) n ns-out lon t s to nrst niors, tn to tir niors n so on Gol: Fin sortst pts (.k.. minimum numr o ops or pt) rom t strt vrtx to vry otr vrtx Dpt 0: Dpt 1:,
41 41 Brt-First Sr Givn rp wit vrtis, V, n s, E, n strtin vrtx, u BFS strts t u ( in t irm to t lt) n ns-out lon t s to nrst niors, tn to tir niors n so on Gol: Fin sortst pts (.k.. minimum numr o ops or pt) rom t strt vrtx to vry otr vrtx Dpt 0: Dpt 1:, Dpt 2:,,, 2 2
42 42 Brt-First Sr Givn rp wit vrtis, V, n s, E, n strtin vrtx, u BFS strts t u ( in t irm to t lt) n ns-out lon t s to nrst niors, tn to tir niors n so on Gol: Fin sortst pts (.k.. minimum numr o ops or pt) rom t strt vrtx to vry otr vrtx Dpt 0: Dpt 1:, Dpt 2:,,, Dpt 3: 2 3 2
43 43 Dvlopin t Aloritm Ky i: Must xplor ll nrr niors or xplorin urtrwy niors From w in n Computr n only o on tin t tim so w v to pik itr or to xplor rom Lt s sy w pik w will in Now wt vrtx soul w xplor (i.. visit niors) nxt? C!! (i w on t w won t in sortst pts.. ) Must xplor ll vrtis t pt i or ny vrtis t pt i Dpt 0: Dpt 1:, Dpt 2:,,, Dpt 3:
44 44 Dvlopin t Aloritm Explorin ll vrtis in t orr ty r oun implis w will xplor ll vrtis t sllowr pt or rtr pt Kp irst-in / irst-out quu (FIFO) o niors oun Put nwly oun vrtis in t k n pull out vrtx rom t ront to xplor nxt W on t wnt to put vrtx in t quu mor tn on mrk vrtx t irst tim w nountr it only llow unmrk vrtis to put in t quu My lso kp prssor strutur tt inits ow vrtx ot isovr (i.. wi vrtx us tis on to oun) Allows us to in sortst-pt k to t strt vrtx
45 45 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0 nil,in Q: nil,in nil,in nil,in nil,in nil,in nil,in
46 46 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0,1 v = nil,in,1 nil,in nil,in nil,in nil,in Q:
47 47 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0,1 v = nil,in,1 nil,in,2 nil,in nil,in Q:
48 48 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0,2,1 v =,1,2,2 nil,in,2 Q:
49 49 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0,2,1 v =,1,2,2 nil,in,2 Q:
50 50 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0,2,1 v =,1,2,2,3,2 Q:
51 51 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0,2,1 v =,1,2,2,3,2 Q:
52 52 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0,2,1 v =,1,2,2,3,2 Q:
53 53 Brt-First Sr Aloritm: BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,0,2,1 v =,1,2,2,3,2 Q:
54 54 Brt-First Sr Sortst pts n oun wlkin prssor vlu rom ny no kwr Exmpl: Sortst pt rom to Strt t Pr[] = (so wlk k to ) Pr[] = (so wlk k to ) Pr[] = (so wlk k to ) Pr[] = nil no prssor, Don!! nil,0,2,1,1,2,2,3,2
55 55 Brt-First Sr Trs BFS (n ltr DFS) will inu tr surp (i.. yli, on prnt ) rom t oriinl rp Rlly BFS ins sust o s tt orm t sortst pts rom t sour to ll otr vrtis n tis sust orms tr,2 nil,0,1,3,1,2,2,2 Oriinl rp, G BFS Inu Tr
56 56 Din ist(s,v) = orrt sortst istn [v] = BFS omput istn p[v] = prssor o v Loop invrint Wt n w sy out t nos in t quu, tir [v] vlus, rltionsip twn [v] n ist[v], t.? Corrtnss Q: nil,0,1 nil,in,1 nil,in nil,in nil,in nil,in BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1
57 57 Corrtnss Din ist(s,v) = orrt sortst istn [v] = BFS omput istn p[v] = prssor o v Loop invrint All vrtis wit p[v]!= nil (i.. lry in t quu or popp rom quu) v [v] = ist(s,v) T istn o t nos in t quu r sort I Q = {v 1, v 2,, v r } tn [v 1 ] <= [v 2 ] <= <= [v r ] T nos in t quu r rom 2 jnt lyrs/lvls i.. [v k ] <= [v 1 ] + 1 Suppos tr is no rom 3 r lvl ([v 1 ] + 2), it must v n oun y som, vi, wr [v i ] = [v 1 ]+1 Q: nil,0,1 nil,in,1 nil,in nil,in nil,in BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,in
58 58 Anlyz t run tim o BFS or rp wit n vrtis n m s Fin T(n,m) How mny tims os loop on lin 5 itrt? Brt-First Sr Q: nil,0,1 nil,in,1 nil,in nil,in nil,in nil,in How mny tims loop on lin 7 itrt? BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1
59 59 Brt-First Sr Anlyz t run tim o BFS or rp wit n vrtis n m s Fin T(n) How mny tims os loop on lin 5 itrt? N tims (on itrtion pr vrtx) How mny tims loop on lin 7 itrt? For vrtx, v, t loop xuts (v) tims = σ v V θ[1 + v ] = θ σ v 1 + θ σ v (v) = Θ (n) + Θ (m) Totl = Θ(n+m) Q: nil,0,1 nil,in,1 nil,in nil,in nil,in BFS(G,u) 1 or vrtx v 2 pr[v] = nil, [v] = in. 3 Q = nw Quu 4 Q.nquu(u), [u]=0 5 wil Q is not mpty 6 v = Q.ront(); Q.quu() 7 or nior, w, o v: 8 i pr[w] < 0 // w not oun 9 Q.nquu(w) 10 pr[w] = v, [w] = [v] + 1 nil,in
60 DEPTH FIRST SEARCH 60
61 61 DFS Applition: Topoloil Sort Brt-irst sr osn't solv ll our prolms. Givn rp o pnnis (tsks, prrquisitis, t.) topoloil sort rts onsistnt orrin o tsks (vrtis) wr no pnnis r violt Mny possil vli topoloil orrins xist EE 109, EE 209, EE 354, EE 454, EE 457, CS104, PHYS 152, CS 201, CS 104, EE 109, CS 170, EE 209, EE 109 EE 209 EE 354 EE 457 EE 454L CS 104 CS 170 CS 201 CS 350 CS 320 CS 401 CS 360
62 62 Topoloil Sort Anotr xmpl Gttin rss Mor Exmpls: Projt mnmnt sulin Buil orr in Mkil or otr ompil projt Cookin usin rip Instrution xution on n outo-orr piplin CPU Proution o output vlus in simultion o omintionl t ntwork Soks Sos Unrwr Pnts Blt Unrsirt Sirt Ti Jkt ttp:// ms/grpalor/toposort.tm
63 63 Topoloil Sort Dos rt-irst sr work? No. Wt i w strt t CS 170 W' o to CS 201L or CS 104 All prnt nos n to omplt or ny il no BFS only urnts som prnt s omplt or il Turns out Dpt-First Sr will prt o our solution EE 109 EE 209 EE 354 EE 457 EE 454L CS 104 CS 170 CS 201 CS 350 CS 320 CS 401 CS 360
64 64 Dpt First Sr Explors ALL ilrn or ompltin prnt Not: BFS omplts prnt or ANY ilrn For DFS lt us ssin: A strt tim wn t no is irst oun A inis tim wn no is omplt I w look t our nos in rvrs orr o inis tim (i.. lst on to inis k to irst on to inis) w rriv t Topoloil orrin!!! EE 457 EE 109 EE 209 EE Rvrs Finis Tim Orr EE 454L 11 CS Strt Tim Finis Tim CS CS CS 350 CS CS 401 CS 360 CS 170, CS 104, CS 201, CS 320, CS 360, CS 477, CS 350, EE 109, EE 209L, EE 354, EE 454L, EE 457
65 65 DFS Aloritm Visit no Mrk s visit (strt) For visit nior, visit it n prorm DFS on ll o tir ilrn Only tn, mrk s inis DFS is rursiv!! I yls in t rp, nsur w on t t ut visitin niors nlssly Color tm s w o Wit = unvisit, Gry = visit ut not inis Blk = inis DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u)
66 66 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u)
67 67 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,):
68 68 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,): DFS-Visit(G,):
69 69 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
70 70 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
71 71 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list: DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
72 72 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list: DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
73 73 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list: DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
74 74 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:, DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
75 75 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,, DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
76 76 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,, DFS-Visit(G,): DFS-Visit(G,):
77 77 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,, DFS-Visit(G,):
78 78 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,, DFS-Visit(G,): DFS-Visit(G,):
79 79 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,, DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
80 80 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,,. DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
81 81 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,,., DFS-Visit(G,): DFS-Visit(G,):
82 82 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,,.,, DFS-Visit(G,):
83 83 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list My itrt trou mny omplt vrtis or inin to lun nw sr rom u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,,.,, DFS-Visit(G,):
84 84 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,,.,,, DFS-Visit(G,):
85 85 Dpt First-Sr DFS-All (G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) 7 rturn inis_list u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) Finis_list:,,,.,,,
86 86 Wit Cyls in t rp ANOTHER EXAMPLE
87 87 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u)
88 88 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) u v DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,):
89 89 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,): DFS-Visit(G,):
90 90 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) u v DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
91 91 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) u v DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
92 92 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
93 93 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) v DFS-Visit(G,): DFS-Visit(G,): u DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
94 94 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) v u DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
95 95 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) v u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
96 96 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFSQ: DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
97 97 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFSQ: v u DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
98 98 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) v u v DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFSQ: DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
99 99 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFSQ: DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
100 100 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFSQ: u DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,): DFS-Visit(G,):
101 101 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) u DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFSQ: DFS-Visit(G,):
102 102 Dpt First-Sr Toposort(G) 1 or vrtx u 2 u.olor = WHITE 3 inis_list = mpty_list 4 or vrtx u o 5 i u.olor == WHITE tn 6 DFS-Visit (G, u, inis_list) DFS-Visit (G, u) 1 u.olor = GRAY 2 or vrtx v in Aj(u) o 3 i v.olor = WHITE tn 4 DFS-Visit (G, v) 5 u.olor = BLACK 6 inis_list.ppn(u) DFSQ:
103 ITERATIVE VERSION 103
104 104 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE st: 13 u.olor = BLACK 14 st.pop_k()
105 105 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE st: 13 u.olor = BLACK 14 st.pop_k()
106 106 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE st: 13 u.olor = BLACK 14 st.pop_k()
107 107 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE st: 13 u.olor = BLACK 14 st.pop_k()
108 108 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE st: 13 u.olor = BLACK 14 st.pop_k()
109 109 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE st: 13 u.olor = BLACK 14 st.pop_k()
110 110 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE 13 u.olor = BLACK 14 st.pop_k() st:
111 111 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE 13 u.olor = BLACK 14 st.pop_k() st:
112 112 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE 13 u.olor = BLACK 14 st.pop_k() st:
113 113 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE 13 u.olor = BLACK 14 st.pop_k() st:
114 114 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE 13 u.olor = BLACK 14 st.pop_k() st:
115 115 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE st: 13 u.olor = BLACK 14 st.pop_k()
116 116 Dpt First-Sr DFS (G,s) 1 or vrtx u 2 u.olor = WHITE 3 st = nw Stk 4 st.pus_k(s) 5 wil st not mpty 6 u = st.k() 7 i u.olor == WHITE tn 8 u.olor = GRAY 9 or vrtx v in Aj(u) o 10 i v.olor == WHITE 11 st.pus_k(v) 12 ls i u.olor!= WHITE st: 13 u.olor = BLACK 14 st.pop_k()
117 117 BFS vs. DFS Aloritm BFS n DFS r mor similr tn you tink Do w us FIFO/Quu (BFS) or LIFO/Stk (DFS) to stor vrtis s w in tm BFS-Visit (G, strt_no) 1 or vrtx u 2 u.olor = WHITE 3 u.pr = nil 4 sq = nw Quu 5 sq.pus_k(strt_no) 6 wil sq not mpty 7 u = sq.pop_ront() 8 i u.olor == WHITE 9 u.olor = GRAY 10 or vrtx v in Aj(u) o 11 sq.pus_k(v) DFS-Visit (G, strt_no) 1 or vrtx u 2 u.olor = WHITE 3 u.pr = nil 4 st = nw Stk 5 st.pus_k(strt_no) 6 wil st not mpty 7 u = st.pop_k() 8 i u.olor == WHITE 9 u.olor = GRAY 10 or vrtx v in Aj(u) o 11 st.pus_k(v)
CS 103 BFS Alorithm. Mark Redekopp
CS 3 BFS Aloritm Mrk Rkopp Brt-First Sr (BFS) HIGHLIGHTED ALGORITHM 3 Pt Plnnin W'v sn BFS in t ontxt o inin t sortst pt trou mz? S?? 4 Pt Plnnin W xplor t 4 niors s on irtion 3 3 3 S 3 3 3 3 3 F I you
More informationlearning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms
rp loritms lrnin ojtivs loritms your sotwr systm sotwr rwr lrn wt rps r in mtmtil trms lrn ow to rprsnt rps in omputrs lrn out typil rp loritms wy rps? intuitivly, rp is orm y vrtis n s twn vrtis rps r
More informationCS 241 Analysis of Algorithms
CS 241 Anlysis o Algorithms Prossor Eri Aron Ltur T Th 9:00m Ltur Mting Lotion: OLB 205 Businss HW6 u lry HW7 out tr Thnksgiving Ring: Ch. 22.1-22.3 1 Grphs (S S. B.4) Grphs ommonly rprsnt onntions mong
More informationMAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017
MAT3707/201/1/2017 Tutoril lttr 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS MAT3707 Smstr 1 Dprtmnt o Mtmtil Sins SOLUTIONS TO ASSIGNMENT 01 BARCODE Din tomorrow. univrsity o sout ri SOLUTIONS TO ASSIGNMENT
More informationGrade 7/8 Math Circles March 4/5, Graph Theory I- Solutions
ulty o Mtmtis Wtrloo, Ontrio N ntr or ution in Mtmtis n omputin r / Mt irls Mr /, 0 rp Tory - Solutions * inits lln qustion. Tr t ollowin wlks on t rp low. or on, stt wtr it is pt? ow o you know? () n
More information16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am
16.unii Introution to Computrs n Prormmin SOLUTIONS to Exmintion /30/0 9:05m - 10:00m Pro. I. Kristin Lunqvist Sprin 00 Grin Stion: Qustion 1 (5) Qustion (15) Qustion 3 (10) Qustion (35) Qustion 5 (10)
More informationAn undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V
Unirt Grphs An unirt grph G = (V, E) V st o vrtis E st o unorr gs (v,w) whr v, w in V USE: to mol symmtri rltionships twn ntitis vrtis v n w r jnt i thr is n g (v,w) [or (w,v)] th g (v,w) is inint upon
More informationPaths. Connectivity. Euler and Hamilton Paths. Planar graphs.
Pths.. Eulr n Hmilton Pths.. Pth D. A pth rom s to t is squn o gs {x 0, x 1 }, {x 1, x 2 },... {x n 1, x n }, whr x 0 = s, n x n = t. D. Th lngth o pth is th numr o gs in it. {, } {, } {, } {, } {, } {,
More informationComplete Solutions for MATH 3012 Quiz 2, October 25, 2011, WTT
Complt Solutions or MATH 012 Quiz 2, Otor 25, 2011, WTT Not. T nswrs ivn r r mor omplt tn is xpt on n tul xm. It is intn tt t mor omprnsiv solutions prsnt r will vlul to stunts in stuyin or t inl xm. In
More informationLecture 20: Minimum Spanning Trees (CLRS 23)
Ltur 0: Mnmum Spnnn Trs (CLRS 3) Jun, 00 Grps Lst tm w n (wt) rps (unrt/rt) n ntrou s rp voulry (vrtx,, r, pt, onnt omponnts,... ) W lso suss jny lst n jny mtrx rprsntton W wll us jny lst rprsntton unlss
More informationCycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!
Outlin Computr Sin 331, Spnnin, n Surphs Mik Joson Dprtmnt o Computr Sin Univrsity o Clry Ltur #30 1 Introution 2 3 Dinition 4 Spnnin 5 6 Mik Joson (Univrsity o Clry) Computr Sin 331 Ltur #30 1 / 20 Mik
More informationCMPS 2200 Fall Graphs. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk
CMPS 2200 Fll 2017 Grps Crol Wnk Sls ourtsy o Crls Lsrson wt ns n tons y Crol Wnk 10/23/17 CMPS 2200 Intro. to Alortms 1 Grps Dnton. A rt rp (rp) G = (V, E) s n orr pr onsstn o st V o vrts (snulr: vrtx),
More informationd e c b a d c b a d e c b a a c a d c c e b
FLAT PEYOTE STITCH Bin y mkin stoppr -- sw trou n pull it lon t tr until it is out 6 rom t n. Sw trou t in witout splittin t tr. You soul l to sli it up n own t tr ut it will sty in pl wn lt lon. Evn-Count
More informationCSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018
CSE 373: Mor on grphs; DFS n BFS Mihl L Wnsy, F 14, 2018 1 Wrmup Wrmup: Disuss with your nighor: Rmin your nighor: wht is simpl grph? Suppos w hv simpl, irt grph with x nos. Wht is th mximum numr of gs
More informationV={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}
Introution Computr Sin & Enginring 423/823 Dsign n Anlysis of Algorithms Ltur 03 Elmntry Grph Algorithms (Chptr 22) Stphn Sott (Apt from Vinohnrn N. Vriym) I Grphs r strt t typs tht r pplil to numrous
More informationV={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}
s s of s Computr Sin & Enginring 423/823 Dsign n Anlysis of Ltur 03 (Chptr 22) Stphn Sott (Apt from Vinohnrn N. Vriym) s of s s r strt t typs tht r pplil to numrous prolms Cn ptur ntitis, rltionships twn
More informationWeighted Graphs. Weighted graphs may be either directed or undirected.
1 In mny ppltons, o rp s n ssot numrl vlu, ll wt. Usully, t wts r nonntv ntrs. Wt rps my tr rt or unrt. T wt o n s otn rrr to s t "ost" o t. In ppltons, t wt my msur o t lnt o rout, t pty o ln, t nry rqur
More informationOutline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example
Outlin Computr Sin 33 Computtion o Minimum-Cost Spnnin Trs Prim's Alorithm Introution Mik Joson Dprtmnt o Computr Sin Univrsity o Clry Ltur #33 3 Alorithm Gnrl Constrution Mik Joson (Univrsity o Clry)
More informationCSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp
CSE 373 Grphs 1: Conpts, Dpth/Brth-First Srh ring: Wiss Ch. 9 slis rt y Mrty Stpp http://www.s.wshington.u/373/ Univrsity o Wshington, ll rights rsrv. 1 Wht is grph? 56 Tokyo Sttl Soul 128 16 30 181 140
More informationSpanning Trees. BFS, DFS spanning tree Minimum spanning tree. March 28, 2018 Cinda Heeren / Geoffrey Tien 1
Spnnn Trs BFS, DFS spnnn tr Mnmum spnnn tr Mr 28, 2018 Cn Hrn / Gory Tn 1 Dpt-rst sr Vsts vrts lon snl pt s r s t n o, n tn ktrks to t rst junton n rsums own notr pt Mr 28, 2018 Cn Hrn / Gory Tn 2 Dpt-rst
More informationGraph Search (6A) Young Won Lim 5/18/18
Grp Sr (6A) Youn Won Lm Copyrt () 2015 2018 Youn W. Lm. Prmon rnt to opy, trut n/or moy t oumnt unr t trm o t GNU Fr Doumntton Ln, Vron 1.2 or ny ltr vron pul y t Fr Sotwr Founton; wt no Invrnt Ston, no
More informationCS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12
Aministrivi: CS61B Ltur #33 Autogrr will run this vning. Toy s Rings: Grph Struturs: DSIJ, Chptr 12 Lst moifi: W Nov 8 00:39:28 2017 CS61B: Ltur #33 1 Why Grphs? For xprssing non-hirrhilly rlt itms Exmpls:
More informationOutline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs
Outlin Computr Sin 33 Computtion o Minimum-Cost Spnnin Trs Prim s Mik Joson Dprtmnt o Computr Sin Univrsity o Clry Ltur #34 Introution Min-Cost Spnnin Trs 3 Gnrl Constrution 4 5 Trmintion n Eiiny 6 Aitionl
More information1 Introduction to Modulo 7 Arithmetic
1 Introution to Moulo 7 Arithmti Bor w try our hn t solvin som hr Moulr KnKns, lt s tk los look t on moulr rithmti, mo 7 rithmti. You ll s in this sminr tht rithmti moulo prim is quit irnt rom th ons w
More informationCSC Design and Analysis of Algorithms. Example: Change-Making Problem
CSC 801- Dsign n Anlysis of Algorithms Ltur 11 Gry Thniqu Exmpl: Chng-Mking Prolm Givn unlimit mounts of oins of nomintions 1 > > m, giv hng for mount n with th lst numr of oins Exmpl: 1 = 25, 2 =10, =
More informationCS 461, Lecture 17. Today s Outline. Example Run
Prim s Algorithm CS 461, Ltur 17 Jr Si Univrsity o Nw Mxio In Prim s lgorithm, th st A mintin y th lgorithm orms singl tr. Th tr strts rom n ritrry root vrtx n grows until it spns ll th vrtis in V At h
More information(Minimum) Spanning Trees
(Mnmum) Spnnn Trs Spnnn trs Kruskl's lortm Novmr 23, 2017 Cn Hrn / Gory Tn 1 Spnnn trs Gvn G = V, E, spnnn tr o G s onnt surp o G wt xtly V 1 s mnml sust o s tt onnts ll t vrts o G G = Spnnn trs Novmr
More information12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)
12/3/12 Outlin Prt 10. Grphs CS 200 Algorithms n Dt Struturs Introution Trminology Implmnting Grphs Grph Trvrsls Topologil Sorting Shortst Pths Spnning Trs Minimum Spnning Trs Ciruits 1 Ciruits Cyl 2 Eulr
More informationDepth First Search. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong
Dprtmnt o Computr Sn n Ennrn Cns Unvrsty o Hon Kon W v lry lrn rt rst sr (BFS). Toy, w wll suss ts sstr vrson : t pt rst sr (DFS) lortm. Our susson wll on n ous on rt rps, us t xtnson to unrt rps s strtorwr.
More information5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs
Prt 10. Grphs CS 200 Algorithms n Dt Struturs 1 Introution Trminology Implmnting Grphs Outlin Grph Trvrsls Topologil Sorting Shortst Pths Spnning Trs Minimum Spnning Trs Ciruits 2 Ciruits Cyl A spil yl
More information, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management
nrl tr T is init st o on or mor nos suh tht thr is on sint no r, ll th root o T, n th rminin nos r prtition into n isjoint susts T, T,, T n, h o whih is tr, n whos roots r, r,, r n, rsptivly, r hilrn o
More information5/1/2018. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees
/1/018 W usully no strns y ssnn -lnt os to ll rtrs n t lpt (or mpl, 8-t on n ASCII). Howvr, rnt rtrs our wt rnt rquns, w n sv mmory n ru trnsmttl tm y usn vrl-lnt non. T s to ssn sortr os to rtrs tt our
More informationQUESTIONS BEGIN HERE!
Points miss: Stunt's Nm: Totl sor: /100 points Est Tnnss Stt Univrsity Dprtmnt of Computr n Informtion Sins CSCI 710 (Trnoff) Disrt Struturs TEST for Fll Smstr, 00 R this for strtin! This tst is los ook
More informationECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS
C 24 - COMBINATIONAL BUILDING BLOCKS - INVST 3 DCODS AND NCODS FALL 23 AP FLZ To o "wll" on this invstition you must not only t th riht nswrs ut must lso o nt, omplt n onis writups tht mk ovious wht h
More information4.1 Interval Scheduling. Chapter 4. Greedy Algorithms. Interval Scheduling: Greedy Algorithms. Interval Scheduling. Interval scheduling.
Cptr 4 4 Intrvl Suln Gry Alortms Sls y Kvn Wyn Copyrt 005 Prson-Ason Wsly All rts rsrv Intrvl Suln Intrvl Suln: Gry Alortms Intrvl suln! Jo strts t s n nss t! Two os omptl ty on't ovrlp! Gol: n mxmum sust
More informationCOMP 250. Lecture 29. graph traversal. Nov. 15/16, 2017
COMP 250 Ltur 29 rp trvrsl Nov. 15/16, 2017 1 Toy Rursv rp trvrsl pt rst Non-rursv rp trvrsl pt rst rt rst 2 Hs up! Tr wr w mstks n t sls or S. 001 or toy s ltur. So you r ollown t ltur rorns n usn ts
More informationCS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:
CS2: Grphs Prihr Ch. 4 Rosn Ch. Grphs A olltion of nos n gs Wht n this rprsnt? n A omputr ntwork n Astrtion of mp n Soil ntwork CS2 - Hsh Tls 2 Dirt Grphs Grphs/Ntworks Aroun Us A olltion of nos n irt
More information5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem
Thorm 10-1: Th Hnshkin Thorm Lt G=(V,E) n unirt rph. Thn Prt 10. Grphs CS 200 Alorithms n Dt Struturs v V (v) = 2 E How mny s r thr in rph with 10 vrtis h of r six? 10 * 6 /2= 30 1 Thorm 10-2 An unirt
More informationExam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013
CS Avn Dt Struturs n Algorithms Exm Solution Jon Turnr //. ( points) Suppos you r givn grph G=(V,E) with g wights w() n minimum spnning tr T o G. Now, suppos nw g {u,v} is to G. Dsri (in wors) mtho or
More informationThe University of Sydney MATH 2009
T Unvrsty o Syny MATH 2009 APH THEOY Tutorl 7 Solutons 2004 1. Lt t sonnt plnr rp sown. Drw ts ul, n t ul o t ul ( ). Sow tt s sonnt plnr rp, tn s onnt. Du tt ( ) s not somorp to. ( ) A onnt rp s on n
More informationOpenMx Matrices and Operators
OpnMx Mtris n Oprtors Sr Mln Mtris: t uilin loks Mny typs? Dnots r lmnt mxmtrix( typ= Zro", nrow=, nol=, nm="" ) mxmtrix( typ= Unit", nrow=, nol=, nm="" ) mxmtrix( typ= Int", nrow=, nol=, nm="" ) mxmtrix(
More informationAnnouncements. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk
Grphs & Grph Algorithms Ltur CS Spring 6 Announmnts A6 rls toy: Risk Strt signing with your prtnr sp Prlim usy Not grphs hs r Grphs K 5 K, =...not th kin w mn, nywy Applitions o Grphs Communition ntworks
More informationTangram Fractions Overview: Students will analyze standard and nonstandard
ACTIVITY 1 Mtrils: Stunt opis o tnrm mstrs trnsprnis o tnrm mstrs sissors PROCEDURE Skills: Dsriin n nmin polyons Stuyin onrun Comprin rtions Tnrm Frtions Ovrviw: Stunts will nlyz stnr n nonstnr tnrms
More informationQUESTIONS BEGIN HERE!
Points miss: Stunt's Nm: Totl sor: /100 points Est Tnnss Stt Univrsity Dprtmnt o Computr n Inormtion Sins CSCI 2710 (Trno) Disrt Struturs TEST or Sprin Smstr, 2005 R this or strtin! This tst is los ook
More informationOutline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)
4/25/12 Outlin Prt 10. Grphs CS 200 Algorithms n Dt Struturs Introution Trminology Implmnting Grphs Grph Trvrsls Topologil Sorting Shortst Pths Spnning Trs Minimum Spnning Trs Ciruits 1 2 Eulr s rig prolm
More informationProblem solving by search
Prolm solving y srh Tomáš voo Dprtmnt o Cyrntis, Vision or Roots n Autonomous ystms Mrh 5, 208 / 3 Outlin rh prolm. tt sp grphs. rh trs. trtgis, whih tr rnhs to hoos? trtgy/algorithm proprtis? Progrmming
More information# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.
How os it work? Pl vlu o imls rprsnt prts o whol numr or ojt # 0 000 Tns o thousns # 000 # 00 Thousns Hunrs Tns Ons # 0 Diml point st iml pl: ' 0 # 0 on tnth n iml pl: ' 0 # 00 on hunrth r iml pl: ' 0
More informationb. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?
MATH 3012 Finl Exm, My 4, 2006, WTT Stunt Nm n ID Numr 1. All our prts o this prolm r onrn with trnry strings o lngth n, i.., wors o lngth n with lttrs rom th lpht {0, 1, 2}.. How mny trnry wors o lngth
More informationN=4 L=4. Our first non-linear data structure! A graph G consists of two sets G = {V, E} A set of V vertices, or nodes f
lulu jwtt pnlton sin towr ounrs hpl lpp lu Our irst non-linr t strutur! rph G onsists o two sts G = {V, E} st o V vrtis, or nos st o E s, rltionships twn nos surph G onsists o sust o th vrtis n s o G jnt
More informationMath 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.
Nm: UCA ID Numr: Stion lttr: th 61 : Disrt Struturs Finl Exm Instrutor: Ciprin nolsu You hv 180 minuts. No ooks, nots or lultors r llow. Do not us your own srth ppr. 1. (2 points h) Tru/Fls: Cirl th right
More informationRound 7: Graphs (part I)
Roun 7: Grphs (prt I) Tommi Junttil Alto Univrsity Shool o Sin Dprtmnt o Computr Sin CS-A40 Dt Struturs n Alorithms Autumn 207 Tommi Junttil (Alto Univrsity) Roun 7 CS-A40 / Autumn 207 / 55 Topis: Grphs
More informationSeven-Segment Display Driver
7-Smnt Disply Drivr, Ron s in 7-Smnt Disply Drivr, Ron s in Prolm 62. 00 0 0 00 0000 000 00 000 0 000 00 0 00 00 0 0 0 000 00 0 00 BCD Diits in inry Dsin Drivr Loi 4 inputs, 7 outputs 7 mps, h with 6 on
More informationStrongly connected components. Finding strongly-connected components
Stronly onnt omponnts Fnn stronly-onnt omponnts Tylr Moor stronly onnt omponnt s t mxml sust o rp wt rt pt twn ny two vrts SE 3353, SMU, Dlls, TX Ltur 9 Som sls rt y or pt rom Dr. Kvn Wyn. For mor normton
More informationMath 166 Week in Review 2 Sections 1.1b, 1.2, 1.3, & 1.4
Mt 166 WIR, Sprin 2012, Bnjmin urisp Mt 166 Wk in Rviw 2 Stions 1.1, 1.2, 1.3, & 1.4 1. S t pproprit rions in Vnn irm tt orrspon to o t ollowin sts. () (B ) B () ( ) B B () (B ) B 1 Mt 166 WIR, Sprin 2012,
More informationImproving Union. Implementation. Union-by-size Code. Union-by-Size Find Analysis. Path Compression! Improving Find find(e)
POW CSE 36: Dt Struturs Top #10 T Dynm (Equvln) Duo: Unon-y-Sz & Pt Comprsson Wk!! Luk MDowll Summr Qurtr 003 M! ZING Wt s Goo Mz? Mz Construton lortm Gvn: ollton o rooms V Conntons twn t rooms (ntlly
More informationCS September 2018
Loil los Distriut Systms 06. Loil los Assin squn numrs to msss All ooprtin prosss n r on orr o vnts vs. physil los: rport tim o y Assum no ntrl tim sour Eh systm mintins its own lol lo No totl orrin o
More informationSolutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1
Solutions for HW Exris. () Us th rurrn rltion t(g) = t(g ) + t(g/) to ount th numr of spnning trs of v v v u u u Rmmr to kp multipl gs!! First rrw G so tht non of th gs ross: v u v Rursing on = (v, u ):
More informationDivided. diamonds. Mimic the look of facets in a bracelet that s deceptively deep RIGHT-ANGLE WEAVE. designed by Peggy Brinkman Matteliano
RIGHT-ANGLE WEAVE Dv mons Mm t look o ts n rlt tt s ptvly p sn y Py Brnkmn Mttlno Dv your mons nto trnls o two or our olors. FCT-SCON0216_BNB66 2012 Klm Pulsn Co. Ts mtrl my not rprou n ny orm wtout prmsson
More informationIn which direction do compass needles always align? Why?
AQA Trloy Unt 6.7 Mntsm n Eltromntsm - Hr 1 Complt t p ll: Mnt or s typ o or n t s stronst t t o t mnt. Tr r two typs o mnt pol: n. Wrt wt woul ppn twn t pols n o t mnt ntrtons low: Drw t mnt l lns on
More informationECE 407 Computer Aided Design for Electronic Systems. Circuit Modeling and Basic Graph Concepts/Algorithms. Instructor: Maria K. Michael.
0 Computr i Dsign or Eltroni Systms Ciruit Moling n si Grph Conptslgorithms Instrutor: Mri K. Mihl MKM - Ovrviw hviorl vs. Struturl mols Extrnl vs. Intrnl rprsnttions Funtionl moling t Logi lvl Struturl
More informationMinimum Spanning Trees
Yufi Tao ITEE Univrsity of Qunslan In tis lctur, w will stuy anotr classic prolm: finin a minimum spannin tr of an unirct wit rap. Intrstinly, vn tou t prolm appars ratr iffrnt from SSSP (sinl sourc sortst
More information(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely
. DETERMINANT.. Dtrminnt. Introution:I you think row vtor o mtrix s oorint o vtors in sp, thn th gomtri mning o th rnk o th mtrix is th imnsion o th prlllppi spnn y thm. But w r not only r out th imnsion,
More informationCSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review
rmup CSE 7: AVL trs rmup: ht is n invrint? Mihl L Friy, Jn 9, 0 ht r th AVL tr invrints, xtly? Disuss with your nighor. AVL Trs: Invrints Intrlu: Exploring th ln invrint Cor i: xtr invrint to BSTs tht
More informationOutline. Binary Tree
Outlin Similrity Srh Th Binry Brnh Distn Nikolus Austn nikolus.ustn@s..t Dpt. o Computr Sins Univrsity o Slzur http://rsrh.uni-slzur.t 1 Binry Brnh Distn Binry Rprsnttion o Tr Binry Brnhs Lowr Boun or
More informationDesigning A Concrete Arch Bridge
This is th mous Shwnh ri in Switzrln, sin y Rort Millrt in 1933. It spns 37.4 mtrs (122 t) n ws sin usin th sm rphil mths tht will monstrt in this lsson. To pro with this lsson, lik on th Nxt utton hr
More informationIndices. Indices. Curriculum Ready ACMNA: 209, 210, 212,
Inis Inis Curriulum Ry ACMNA: 09, 0,, 6 www.mtltis.om Inis INDICES Inis is t plurl or inx. An inx is us to writ prouts o numrs or pronumrls sily. For xmpl is tully sortr wy o writin #. T is t inx. Anotr
More informationThe University of Sydney MATH2969/2069. Graph Theory Tutorial 5 (Week 12) Solutions 2008
Th Univrsity o Syny MATH2969/2069 Grph Thory Tutoril 5 (Wk 12) Solutions 2008 1. (i) Lt G th isonnt plnr grph shown. Drw its ul G, n th ul o th ul (G ). (ii) Show tht i G is isonnt plnr grph, thn G is
More informationEE1000 Project 4 Digital Volt Meter
Ovrviw EE1000 Projt 4 Diitl Volt Mtr In this projt, w mk vi tht n msur volts in th rn o 0 to 4 Volts with on iit o ury. Th input is n nlo volt n th output is sinl 7-smnt iit tht tlls us wht tht input s
More informationCOMP108 Algorithmic Foundations
Grdy mthods Prudn Wong http://www.s.liv..uk/~pwong/thing/omp108/01617 Coin Chng Prolm Suppos w hv 3 typs of oins 10p 0p 50p Minimum numr of oins to mk 0.8, 1.0, 1.? Grdy mthod Lrning outoms Undrstnd wht
More informationConstructive Geometric Constraint Solving
Construtiv Gomtri Constrint Solving Antoni Soto i Rir Dprtmnt Llngutgs i Sistms Inormàtis Univrsitt Politèni Ctluny Brlon, Sptmr 2002 CGCS p.1/37 Prliminris CGCS p.2/37 Gomtri onstrint prolm C 2 D L BC
More informationGraphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1
CSC 00 Disrt Struturs : Introuon to Grph Thory Grphs Grphs CSC 00 Disrt Struturs Villnov Univrsity Grphs r isrt struturs onsisng o vrs n gs tht onnt ths vrs. Grphs n us to mol: omputr systms/ntworks mthml
More informationPlanar Upward Drawings
C.S. 252 Pro. Rorto Tmssi Computtionl Gomtry Sm. II, 1992 1993 Dt: My 3, 1993 Sri: Shmsi Moussvi Plnr Upwr Drwings 1 Thorm: G is yli i n only i it hs upwr rwing. Proo: 1. An upwr rwing is yli. Follow th
More information0.1. Exercise 1: the distances between four points in a graph
Mth 707 Spring 2017 (Drij Grinrg): mitrm 3 pg 1 Mth 707 Spring 2017 (Drij Grinrg): mitrm 3 u: W, 3 My 2017, in lss or y mil (grinr@umn.u) or lss S th wsit or rlvnt mtril. Rsults provn in th nots, or in
More informationCMSC 451: Lecture 2 Graph Basics Thursday, Aug 31, 2017
Dv Mount CMSC 45: Ltur Grph Bsis Thursy, Au, 07 Rin: Chpt. in KT (Klinr n Tros) n Chpt. in DBV (Dsupt, Ppimitriou, n Vzirni). Som o our trminoloy irs rom our txt. Grphs n Dirphs: A rph G = (V, E) is strutur
More informationAnnouncements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms
Grphs & Grph Algorithms Ltur CS Fll 5 Announmnts Upoming tlk h Mny Crrs o Computr Sintist Or how Computr Sin gr mpowrs you to o muh mor thn o Dn Huttnlohr, Prossor in th Dprtmnt o Computr Sin n Johnson
More informationDFA Minimization. DFA minimization: the idea. Not in Sipser. Background: Questions: Assignments: Previously: Today: Then:
Assinmnts: DFA Minimiztion CMPU 24 Lnu Tory n Computtion Fll 28 Assinmnt 3 out toy. Prviously: Computtionl mols or t rulr lnus: DFAs, NFAs, rulr xprssions. Toy: How o w in t miniml DFA or lnu? Tis is t
More informationCS150 Sp 98 R. Newton & K. Pister 1
Outin Cok Synronous Finit- Mins Lst tim: Introution to numr systms: sin/mnitu, ons ompmnt, twos ompmnt Rviw o ts, ip ops, ountrs Tis tur: Rviw Ts & Trnsition Dirms Impmnttion Usin D Fip-Fops Min Equivn
More informationWhy the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.
Why th Juntion Tr lgorithm? Th Juntion Tr lgorithm hris Willims 1 Shool of Informtis, Univrsity of Einurgh Otor 2009 Th JT is gnrl-purpos lgorithm for omputing (onitionl) mrginls on grphs. It os this y
More informationGraphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari
Grphs CSC 1300 Disrt Struturs Villnov Univrsity Grphs Grphs r isrt struturs onsis?ng of vr?s n gs tht onnt ths vr?s. Grphs n us to mol: omputr systms/ntworks mthm?l rl?ons logi iruit lyout jos/prosss f
More informationMCS100. One can begin to reason only when a clear picture has been formed in the imagination.
642 ptr 10 Grps n Trs 46. Imin tt t irmsown low is mp wit ountris ll. Is it possil to olor t mp wit only tr olors so tt no two jnt ountris v t sm olor? To nswr tis qustion, rw n nlyz rp in wi ountry is
More informationOutlines: Graphs Part-4. Applications of Depth-First Search. Directed Acyclic Graph (DAG) Generic scheduling problem.
Outlins: Graps Part-4 Applications o DFS Elmntary Grap Aloritms Topoloical Sort o Dirctd Acyclic Grap Stronly Connctd Componnts PART-4 1 2 Applications o Dpt-First Sarc Topoloical Sort: Usin dpt-irst sarc
More informationSection 10.4 Connectivity (up to paths and isomorphism, not including)
Toy w will isuss two stions: Stion 10.3 Rprsnting Grphs n Grph Isomorphism Stion 10.4 Conntivity (up to pths n isomorphism, not inluing) 1 10.3 Rprsnting Grphs n Grph Isomorphism Whn w r working on n lgorithm
More informationCSE 332. Data Structures and Parallelism
Am Blnk Ltur 20 Wntr 2017 CSE 332 Dt Struturs n Prlllsm CSE 332: Dt Struturs n Prlllsm Grps 1: Wt s Grp? DFS n BFS LnkLsts r to Trs s Trs r to... 1 Wr W v Bn Essntl ADTs: Lsts, Stks, Quus, Prorty Quus,
More informationCSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2
Am Blnk Ltur 19 Summr 2015 CSE 332: Dt Astrtons CSE 332 Grps 1: Wt s Grp? DFS n BFS Dt Astrtons LnkLsts r to Trs s Trs r to... 1 A Grp s Tny... 2 Wr W v Bn Essntl ADTs: Lsts, Stks, Quus, Prorty Quus, Hps,
More information10/30/12. Today. CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James. DFS algorithm. Reachability Algorithms
0/0/ CS/ENGRD 0 Ojt- Orint Prormmin n Dt Strutur Fll 0 Dou Jm Ltur 9: DFS, BFS & Shortt Pth Toy Rhility Dpth-Firt Srh Brth-Firt Srh Shortt Pth Unwiht rph Wiht rph Dijktr lorithm Rhility Alorithm Dpth Firt
More informationOrganization. Dominators. Control-flow graphs 8/30/2010. Dominators, control-dependence. Dominator relation of CFGs
Orniztion Domintors, ontrol-pnn n SSA orm Domintor rltion o CFGs postomintor rltion Domintor tr Computin omintor rltion n tr Dtlow lorithm Lnur n Trjn lorithm Control-pnn rltion SSA orm Control-low rphs
More information(4, 2)-choosability of planar graphs with forbidden structures
1 (4, )-oosility o plnr rps wit orin struturs 4 5 Znr Brikkyzy 1 Cristopr Cox Mil Diryko 1 Kirstn Honson 1 Moit Kumt 1 Brnr Liiký 1, Ky Mssrsmit 1 Kvin Moss 1 Ktln Nowk 1 Kvin F. Plmowski 1 Drrik Stol
More informationPresent state Next state Q + M N
Qustion 1. An M-N lip-lop works s ollows: I MN=00, th nxt stt o th lip lop is 0. I MN=01, th nxt stt o th lip-lop is th sm s th prsnt stt I MN=10, th nxt stt o th lip-lop is th omplmnt o th prsnt stt I
More informationTheorem 1. An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.
Cptr 11: Trs 11.1 - Introuton to Trs Dnton 1 (Tr). A tr s onnt unrt rp wt no sp ruts. Tor 1. An unrt rp s tr n ony tr s unqu sp pt twn ny two o ts vrts. Dnton 2. A root tr s tr n w on vrtx s n snt s t
More informationPhysics 222 Midterm, Form: A
Pysis 222 Mitrm, Form: A Nm: Dt: Hr r som usul onstnts. 1 4πɛ 0 = 9 10 9 Nm 2 /C 2 µ0 4π = 1 10 7 tsl s/c = 1.6 10 19 C Qustions 1 5: A ipol onsistin o two r point-lik prtils wit q = 1 µc, sprt y istn
More informationS i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.
S i m p l i y i n g A l g r SIMPLIFYING ALGEBRA www.mthltis.o.nz Simpliying SIMPLIFYING Algr ALGEBRA Algr is mthmtis with mor thn just numrs. Numrs hv ix vlu, ut lgr introus vrils whos vlus n hng. Ths
More informationEdge-Triggered D Flip-flop. Formal Analysis. Fundamental-Mode Sequential Circuits. D latch: How do flip-flops work?
E-Trir D Flip-Flop Funamntal-Mo Squntial Ciruits PR A How o lip-lops work? How to analys aviour o lip-lops? R How to sin unamntal-mo iruits? Funamntal mo rstrition - only on input an an at a tim; iruit
More informationWeighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths
Dt Strutur LECTURE Shortt pth lgorithm Proprti of hortt pth Bllmn-For lgorithm Dijktr lgorithm Chptr in th txtook (pp ). Wight grph -- rminr A wight grph i grph in whih g hv wight (ot) w(v i, v j ) >.
More informationModule graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura
Moul grph.py CS 231 Nomi Nishimur 1 Introution Just lik th Python list n th Python itionry provi wys of storing, ssing, n moifying t, grph n viw s wy of storing, ssing, n moifying t. Bus Python os not
More informationApplications: The problem has several applications, for example, to compute periods of maximum net expenses for a design department.
A Gntl Introution to Aloritms: Prt III Contnts o Prt I: 1. Mr: (to mr two sort lists into sinl sort list.). Bul Sort 3. Mr Sort: 4. T Bi-O, Bi-Θ, Bi-Ω nottions: symptoti ouns Contnts o Prt II: 5. Bsis
More informationCMSC 451: Lecture 4 Bridges and 2-Edge Connectivity Thursday, Sep 7, 2017
Rn: Not ovr n or rns. CMSC 451: Ltr 4 Brs n 2-E Conntvty Trsy, Sp 7, 2017 Hr-Orr Grp Conntvty: (T ollown mtrl ppls only to nrt rps!) Lt G = (V, E) n onnt nrt rp. W otn ssm tt or rps r onnt, t somtms t
More informationGreedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016
Ltur 4 Gry Algorithms, Ativity Sltion, Minimum Spnning Trs Sris: Logn Short (5), Virgini Dt: My, Gry Algorithms Suppos w wnt to solv prolm, n w r l to om up with som rursiv ormultion o th prolm tht woul
More informationRegister Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012
Rgistr Allotion W now r l to o rgistr llotion on our intrfrn grph. W wnt to l with two typs of onstrints: 1. Two vlus r liv t ovrlpping points (intrfrn grph) 2. A vlu must or must not in prtiulr rhitturl
More informationGraph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2
Grt Thortil Is In Computr Sin Vitor Amhik CS 15-251 Ltur 9 Grphs - II Crngi Mllon Univrsity Grph Isomorphism finition. Two simpl grphs G n H r isomorphi G H if thr is vrtx ijtion V H ->V G tht prsrvs jny
More informationa g f 8 e 11 Also: Minimum degree, maximum degree, vertex of degree d 1 adjacent to vertex of degree d 2,...
Warmup: Lt b 2 c 3 d 1 12 6 4 5 10 9 7 a 8 11 (i) Vriy tat G is connctd by ivin an xampl o a walk rom vrtx a to ac o t vrtics b. (ii) Wat is t sortst pat rom a to c? to? (iii) Wat is t lonst pat rom a
More information