Chapter 16. Shortest Paths Shortest Weighted Paths

Size: px
Start display at page:

Download "Chapter 16. Shortest Paths Shortest Weighted Paths"

Transcription

1 Chpter 6 Shortet Pth Given grph where ege re lle with weight (or itne) n oure vertex, wht i the hortet pth etween the oure n ome other vertex? Prolem requiring u to nwer uh querie re roly known hortet-pth prolem. Shortet-pth prolem ome in everl flvor. For exmple, the ingle-oure horetet pth prolem require fining the hortet pth etween given oure n ll other vertie; the ingle-pir hortet pth prolem require fining the hortet pth etween given oure n given etintion vertex; the ll-pir hortet pth prolem require fining the hortet pth etween ll pir of vertie. In thi hpter, we onier the ingle-oure hortet-pth prolem n iu two lgorithm for thi prolem: Dijktr n Bellmn-For lgorithm. Dijktr lgorithm i more effiient ut it i motly equentil n it work only for grph where ege weight re non-negtive. Bellmn-For lgorithm i goo prllel lgorithm n work for ll grph ut require ignifintly more work. 6. Shortet Weighte Pth Conier weighte grph G = (V, E, w), w : E R. The grph n either e irete or unirete. For onveniene we efine w(u, v) = if (u, v) E. We efine the weight of pth the um of the weight of the ege long tht pth. 7

2 76 CHAPTER 6. SHORTEST PATHS Exmple 6.. In the following grph the weight of the pth,,, e i 6. The weight of the pth,,, i. 7 e 4 6 For weighte grph G(V, E, w) hortet weighte pth from vertex u to vertex v i pth from u to v with minimum weight. There might e multiple pth with equl weight, n if o they re ll hortet weighte pth from u to v. We ue δ G (u, v) to inite the weight of hortet pth from u to v. Quetion 6.. Wht hppen if we hnge the weight of the ege (, ) from 7 to 7? If we llow for negtive weight ege then it i poile to rete hortet pth of infinite length (in ege) n whoe weight i. In Exmple 6. if we hnge the weight of the ege (, ) to 7 the hortet pth etween n e h weight ine pth n keep going roun the yle,,, reuing it weight y 4 eh time roun. Rell tht pth llow repete vertie - imple pth oe not. For thi reon, when omputing hortet pth we will nee to e reful out yle of negtive weight. A we will ee, even if there re no negtive weight yle, negtive ege weight mke fining hortet pth more iffiult. We will therefore firt onier the prolem of fining hortet pth when there re no negtive ege weight. A riefly mentione efore, in thi hpter, we re interete in fining ingleoure hortet pth, efine follow. Prolem 6. (Single-Soure Shortet Pth (SSSP)). Given weighte grph G = (V, E, w) n oure vertex, the ingle-oure hortet pth (SSSP) prolem i to fin hortet weighte pth from to every other vertex in V. Although there n e mny equl weight hortet pth etween two vertie, the prolem only require fining one. Alo ometime we only re out the weight δ(u, v) of the hortet pth n not the pth itelf. In Chpter 4 we w how Breth-Firt Serh (BFS) n e ue to olve the ingle-oure hortet pth prolem on grph without ege weight, or, equivlently, where ll ege hve weight. April 9, (DRAFT, PPAP)

3 6.. DIJKSTRA S ALGORITHM 77 Quetion 6.4. Cn we ue BFS to olve the ingle-oure hortet pth prolem on weighte grph? Ignoring weight n uing BFS, unfortuntely, oe not work on weighte grph. Exmple 6.. To ee why BFS oe not work, onier the following irete grph with vertie: BFS firt viit n then. When it viit, it ign it n inorret weight of. Sine BFS never viit gin, it will not fin the hortet pth going trough, whih hppen to e horter. Exmple 6.6. Another grph where BFS fil to fin the hortet pth orretly The reon why BFS work on unweighte grph i quite intereting n helpful for unertning other hortet pth lgorithm. The key ie ehin BFS i to viit vertie in orer of their itne from the oure, viiting loet vertie firt, n the next loet, n o on. More peifilly, for eh frontier F i (t roun i), BFS h the orret itne from the oure to eh vertex in the frontier. It then n etermine the orret itne for unenountere neighor tht re itne one further wy (on the next frontier). We will ue imilr ie for weighte pth. 6. Dijktr Algorithm Conier vrint of the SSSP prolem, where ll the weight on the ege re non-negtive (i.e. w : E R ). We refer to thi the SSSP + prolem. Dijktr lgorithm olve effiiently the SSSP + prolem. Dijktr lgorithm i importnt eue it i effiient n lo eue it i very elegnt exmple of n effiient greey lgorithm tht gurntee optimlity (of olution) for nontrivil prolem. April 9, (DRAFT, PPAP)

4 78 CHAPTER 6. SHORTEST PATHS In thi etion, we re going to (re-)iover thi lgorithm y tking vntge of propertie of grph n hortet pth. Before going further we note tht ine no ege hve negtive weight, there nnot e negtive weight yle. Therefore one n never mke pth horter y viiting vertex twie i.e. pth tht yle k to vertex nnot hve leer weight thn the pth tht en t the firt viit to the vertex. When erhing for hortet pth, we thu hve to onier only the imple pth. Quetion 6.7. Give rute-fore lgorithm for fining the hortet pth? Let u trt with rute fore lgorithm for the SSSP + prolem, tht, for eh vertex, onier ll imple pth etween the oure n the vertex n elet the hortet uh pth. Quetion 6.8. How mny imple pth n there e etween two vertie in grph? Unfortuntely there n e n exponentil numer of pth etween ny pir of vertie, o ny lgorithm tht trie to look t ll pth i not likely to le eyon very mll intne. We therefore hve to try to reue the work. Towr thi en we note tht the u-pth of hortet pth mut lo e hortet pth etween their en vertie, n look t how thi n help. Thi u-pth property i key property of hortet pth. We re going to ue thi property oth now to erive Dijktr lgorithm, n lo gin in the next etion to erive Bellmn-For lgorithm for the SSSP prolem on grph tht o llow negtive ege weight. Exmple 6.9. If hortet pth from Pitturgh to Sn Frnio goe through Chigo, then tht hortet pth inlue the hortet pth from Pitturgh to Chigo. To ee how u-pth property n e helpful, onier the grph in Exmple 6. n uppoe tht n orle h tol u the hortet pth to ll vertie exept for the vertex v. We wnt to fin the hortet pth to v. Quetion 6.. Cn you fin the hortet pth to v? By inpeting the grph, we know tht the hortet pth to v goe through either one of,, or. Furthermore, y u-pth property, we know tht the hortet pth to v onit of the hortet pth to one of,, or, n the ege to v. Thu, ll we hve to o i to fin the u mong the in-neighor of v tht minimize the weight of the pth to v, i.e. δ G (, u) plu the itionl ege weight to get to v. Quetion 6.. Coul the hortet-pth e going through v? If o, then re we till gurntee to fin hortet pth? April 9, (DRAFT, PPAP)

5 6.. DIJKSTRA S ALGORITHM 79 Note tht we hve eie to fin only the hortet pth tht re imple, whih nnot go through v itelf. Exmple 6.. In the following grph G, uppoe tht we hve foun the hortet pth from the oure to ll the other vertie exept for v; eh vertex i lele with it itne to. The weight of the hortet pth to v i min δ G (, ) +, δ G (, ) + 6, δ G (, ) +. The hortet pth goe through the vertex (,, or ) tht minimize the weight, whih in thi e i vertex. X v 7 Let now onier the e where the orle gve u the hortet pth to ll ut two of the vertie u, v. Quetion 6.. Cn we fin the hortet pth to ny one of u or v? Let X enote the et of vertie for whih we know the hortet pth. We my think of thi et the viite et in grph erh. Let lulte for u (n v) the hortet pth tht goe through neighor in X n then goe to u (v). Conier now the hortet of thee two itne n ume without lo of generlity tht it i the pth to u. Quetion 6.4. Coul the hortet pth to u e thi pth? Sine oure i in X, we know tht the hortet pth to u ro out from X vi ome ege tht goe to either u or v. Sine we know tht the weight of uh pth to u i the mller, n ine ll ege weight re non-negtive, there nnot e horter pth tht goe to u n thn ome k to v gin. We thu onlue tht the hortet pth to v i the pth tht we hve foun y oniering ll inoming ege from X. Exmple 6. illutrte thi. April 9, (DRAFT, PPAP)

6 8 CHAPTER 6. SHORTEST PATHS Exmple 6.. In the following grph uppoe tht we hve foun the hortet pth from the oure to ll the vertie in X. The hortet pth re inite y lel next to the vertie. The hortet pth from the oure to ny vertex in Y i the pth to vertex with weight followe y the ege (, v) with weight 4 n hene totl weight 9. If ege weight re non-negtive there nnot e ny horter wy to get to v, whtever w(u, v) i, therefore we know tht δ(, v) = 9. X 8 6 v u. Quetion 6.6. Cn you ee how we n generlize thi ie? Let try to generlize the rgument n onier the e where the orle tell u the hortet pth from to to ome uet of the vertie X V with X. Alo let efine Y to e the vertie not in X, i.e. V \ X. The quetion i whether we n effiiently etermine the hortet pth to ny one of the vertie in Y. Quetion 6.7. Wht woul e the point of oing tht? If we oul o thi, then we woul hve rnk to repetely new vertie to X until we re one. A in grph erh, we ll the et of vertie tht re neighor of X ut not in X, i.e. N + (X) \ X, the frontier. It houl e ler tht ny pth tht leve X h to go through frontier vertex on the wy out. Therefore for every v Y the hortet pth from mut trt in X, ine X, n then leve X vi vertex in the frontier. Quetion 6.8. Cn you ue thi property to ientify vertex v Y tht i no frther from the oure thn ny other vertex in Y? April 9, (DRAFT, PPAP)

7 6.. DIJKSTRA S ALGORITHM 8 Conier the vertex v Y tht h n ege to ome lrey viite vertex x X n tht minimize the um δx + w(x, v). Sine ll pth to Y mut go through the frontier when exiting X, n ine ege re non-negtive, u-pth nnot e longer thn the full pth. Thu, no other vertex in Y n e loer to the oure thn x. See Exmple 6.9. Furthermore, ine ll other vertie in Y re frther thn v n ine ll ege re non-negtive, the hortet pth for v i δx + w(x, v). Exmple 6.9. In the following grph uppoe tht we hve foun the hortet pth from the oure to ll the vertie in X (mrke y numer next to the vertie). The hortet pth from the oure to ny vertex in Y i the pth to vertex with weight followe y the ege (, v) with weight 4 n hene totl weight 9. If ege weight re non-negtive there nnot e ny horter wy to get to v, whtever w(u, v) i, therefore we know tht δ(, v) = 9. X Y= V \ X v t 4 u. Thi intuition i tte n prove in Lemm 6.. The Lemm tell u tht one we know the hortet pth to et X we n more vertie to X with their hortet pth. Thi give u rnk tht n hurn out t let one new vertex on eh roun. Dijktr lgorithm imply oe extly thi: it turn the rnk until ll vertie re viite. Quetion 6.. You might hve notie tht the terminology tht we ue in explining Dijktr lgorithm loely relte to tht of grph erh. Doe thi lgorithm remin you of prtiulr grph erh tht we iue? Rell tht priority-firt erh i grph erh in whih on eh tep we viit the frontier vertie with the highet priority. In our e the viite et i X, n the priority i efine in term of p(v), the hortet-pth weight oniting of pth to x X with n itionl ege from x to v. In other wor, thi lgorithm i tully n intne of priority-firt erh. We re now rey to efine preiely Dijktr lgorithm. April 9, (DRAFT, PPAP)

8 8 CHAPTER 6. SHORTEST PATHS Lemm 6. (Dijktr Property). Conier (irete) weighte grph G = (V, E, w), w : E R, n oure vertex V. Conier ny prtitioning of the vertie V into X n Y = V \ X with X, n let then min p(y) = min δ G(, y). y Y y Y p(v) min x X (δ G(, x) + w(x, v)) X Y=V \ X v x v t v m In Englih: The overll hortet-pth weight from vi vertex in X iretly to neighor in Y (in the frontier) i hort ny pth from to ny vertex in Y. Proof. Conier vertex v m Y uh tht δ G (, v m ) = min v Y δ G (, v), n hortet pth from to v m in G. The pth mut go through n ege from vertex v x X to vertex v t in Y (ee the figure). Sine there re no negtive weight ege, n the pth to v t i u-pth of the pth to v m, δ G (, v t ) nnot e ny greter thn δ G (, v m ) o it mut e equl. We therefore hve min y Y p(y) δ G (, v t ) = δ G (, v m ) = min y Y δ G (, y), ut the leftmot term nnot e le thn the rightmot, o they mut e equl. Implition: Thi give u wy to eily fin δ G (, v) for t let one vertex v Y. In prtiulr for ll v Y where p(v) = min y Y p(y), it mut e the e tht p(v) = δ G (, v) ine there nnot e horter pth. Alo we nee only onier the frontier vertie in lulting p(v), ine for other in Y, p(y) i infinite. Algorithm 6. (Dijktr Algorithm). For weighte grph G = (V, E, w) n oure, Dijktr lgorithm i priority-firt erh on G trting t with () =, uing priority p(v) = min((x) + w(x, v)) (to e minimize), n etting (v) = p(v) x X when v i viite. Note tht Dijktr lgorithm will viit vertie in non-ereing hortet-pth weight ine on eh roun it viit unviite vertie tht hve the minimum hortet-pth weight from. April 9, (DRAFT, PPAP)

9 6.. DIJKSTRA S ALGORITHM 8 Remrk 6.. It my e tempting to think tht Dijktr lgorithm viit vertie tritly in inreing orer of hortet-pth weight from the oure, viiting vertie with equl hortet-pth weight on the me roun. Thi i not true. To ee thi onier the exmple elow n onvine yourelf tht it oe not ontrit our reoning. Lemm 6.4. Dijktr lgorithm return, (v) = δ G (, v) for v rehle from. Proof. We how tht for eh tep in the lgorithm, for ll x X (the viite et), (x) = δ G (, x). Thi i true t the trt ine X = {} n () =. On eh tep the erh vertie v tht minimize P (v) = min x X ((x) + w(x, v)). By our umption we hve tht (x) = δ G (, x) for x X. By Lemm 6., p(v) = δ G (, v), giving (v) = δ G (, v) for the newly e vertie, mintining the invrint. A with ll priority-firt erhe, it will eventully viit ll rehle v. 6.. Implementing Dijktr Algorithm with Priority Queue We now iu how to implement thi trt lgorithm effiiently uing priority queue to mintin P (v). We ue priority queue tht upport eletemin n inert. The priorityqueue e lgorithm i given in Algorithm 6.. Thi vrint of the lgorithm only one vertex t the time even if there re multiple vertie with equl itne tht oul e e in prllel. It n e me prllel y generlizing priority queue, ut we leve thi n exerie. The lgorithm mintin the viite et X tle mpping eh viite vertex u to (u) = δ G (, u). It lo mintin priority queue Q tht keep the frontier prioritize e on the hortet itne from iretly from vertie in X. On eh roun, the lgorithm elet the vertex x with let itne in the priority queue (Line 9 in the oe) n, if it hn t lrey een viite, viit it y ing (x ) to the tle of viite vertie (Line 6), n then ll it neighor v to Q long with the priority (x) + w(x, v) (i.e. the itne to v through x) (Line 7 n 8). Note tht neighor might lrey e in Q ine it oul hve een e y nother of it in-neighor. Q n therefore ontin uplite entrie for vertex, ut wht i importnt i tht the minimum itne will lwy e pulle out firt. Line hek to ee whether vertex pulle from the priority queue h lrey een viite n ir it if it h. Thi lgorithm i jut onrete implementtion of the previouly erie Dijktr lgorithm. We note tht there re ouple other vrint on Dijktr lgorithm uing Priority Queue. April 9, (DRAFT, PPAP)

10 84 CHAPTER 6. SHORTEST PATHS Algorithm 6. (Dijktr Algorithm uing Priority Queue). funtion ijktrpq(g, ) = let 4 % require: (x ) X, = δ G (, x) 6 {(, y) Q y V \ X} = {( + w(x, y), y) : (x ) X, y N + (x) \ X} 7 % return: {x δ G (, x) : x R G ()} 8 funtion ijktr (X, Q) = 9 e PQ.eleteMin (Q) of (, _) X ((, v), Q ) if (v, ) X then ijktr (X, Q ) 4 ele let 6 X = X {(v, )} 7 funtion relx (Q, (u, w)) = PQ.inert ( + w, u) Q 8 Q = iter relx Q N G (v) 9 in ijktr (X, Q ) en in ijktr ({}, PQ.inert (, ) {}) en Firtly we oul hek inie the relx funtion whether u i lrey in X n if o not inert it into the Priority Queue. Thi oe not ffet the ymptoti work oun ut proly woul give ome improvement in prtie. Another vrint i to eree the priority of the neighor inte of ing uplite to the priority queue. Thi require more powerful priority queue tht upport ereekey funtion. Cot of Dijktr Algorithm. We now onier the work of the Priority Queue verion of Dijktr lgorithm, whoe oe i hown in Algorithm 6.. Let fir onier the ADT tht we will ue long with their ot. For the priority queue, we ume PQ.inert n PQ.eleteMin hve O(log n) work n pn. To repreent the grph, we n either ue tle or n rry, mpping vertie to their neighor long with the weight of the ege in etween. For the purpoe of Dijktr lgorithm, it uffie to ue the tree e ot for tle. Note tht ine we on t upte the grph, we on t nee ingle three rry. To repreent the tle of itne to viite vertie, we n ue tle, n rry equene, or ingle three rry equene. April 9, (DRAFT, PPAP)

11 6.. DIJKSTRA S ALGORITHM 8 Exmple 6.6. An exmple run of Dijktr lgorithm. Note tht fter viiting,, n, the queue Q ontin two itne for orreponing to the two pth from to iovere thu fr. The lgorithm tke the hortet itne n it to X. A imilr itution rie when i viite, ut thi time for. Note tht when i viite, n itionl itne for i e to the priority queue even though it i lrey viite. Reunnt entrie for oth re remove next efore viiting. The vertex e i never viite it i unrehle from. Finlly, notie tht the itne in X never eree. X @ e e e e e e Q e e April 9, (DRAFT, PPAP)

12 86 CHAPTER 6. SHORTEST PATHS Opertion Line # of ll PQ Tree Tle Arry ST Arry eletemin Line 9 O(m) O(log m) inert Line 7 O(m) O(log m) Priority Q totl O(m log m) fin Line O(m) - O(log n) O() O() inert Line 6 O(n) - O(log n) O(n) O() Ditne totl - O(m log n) O(n ) O(m) N G (v) Line 8 O(n) - O(log n) O() - iter Line 8 O(m) - O() O() - Grph e totl - O(m + n log n) O(m) - Figure 6.: The ot for the importnt tep in the lgorithm ijktrpq. To nlyze the work, we lulte the work for eh ifferent kin of opertion n um them up to fin the totl work. Figure 6. ummrize the ot of the opertion, long with the numer of ll me to eh opertion. The lgorithm in inlue ox roun eh opertion on the grph G, the et of viite vertie X, or the priority queue PQ. The PQ.inert in Line i lle only one, o we n fely ignore it. Of the remining opertion, The iter n N G (v) on Line 8 re on the grph, Line n 6 re on the tle of viite vertie X, n Line 9 n 7 re on the priority queue Q. We n lulte the totl numer of ll to eh opertion y noting tht the oy of the let trting on Line i only run one for eh vertex. Thu, Line 6 n N G (v) on Line 8 re only lle O(n) time. All other opertion re performe one for eh ege. The totl work for Dijktr lgorithm uing tree tle i therefore O(m log m + m log n + m + n log n). Sine m n, the totl work i O(m log n). Sine the lgorithm i equentil, the pn i the me the work. Be on the tle one houl note tht when uing either tree tle or ingle three equene, the ot i no more thn the ot of the priority queue opertion. Therefore there i no ymptoti vntge of uing one over the other; there might, however, e ifferene in ontnt ftor. One houl lo note tht uing regulr purely funtionl rry i not goo ie, eue the ot i then ominte y the inertion n the lgorithm run in Θ(n ) work. 6. The Bellmn For Algorithm We now turn to olving the ingle oure hortet pth prolem in the generl e where we llow negtive weight in the grph. One might k how negtive weight mke ene. When oniering itne on mp for exmple, negtive weight o not mke ene (t let without time trvel), ut mny other prolem reue to hortet pth, n in thee reution April 9, (DRAFT, PPAP)

13 6.. THE BELLMAN FORD ALGORITHM 87 negtive weight o how up. Before proeeing we note tht if there i negtive weight yle (the um of weight on the yle i negtive) rehle from the oure, then there nnot e olution to the ingleoure hortet pth prolem, iue erlier. In uh e, we woul like the lgorithm to inite tht uh yle exit n terminte. Exerie 6.7. Conier the following urreny exhnge prolem: given the et urrenie, et of exhnge rte etween them, n oure urreny, fin for eh other urreny v the et equene of exhnge to get from to v. Hint: how n you onvert multiplition to ition. Exerie 6.8. In your olution to the previou exerie n you get negtive weight yle? If o, wht oe thi men? Quetion 6.9. Why n t we ue Dijktr lgorithm to ompute hortet pth when there re negtive ege? Rell tht in our evelopment of Dijktr lgorithm we ume non-negtive ege weight. Thi oth llowe u to only onier imple pth (with no yle) ut more importntly plye ritil role in rguing the orretne of Dijktr property. More peifilly, Dijktr lgorithm i e on the umption tht the hortet pth to the vertex v in the frontier tht i loet to the et of viite vertie, whoe itne hve een etermine, n e etermine y oniering jut the inoming ege of v. With negtive ege weight, thi i not true nymore, eue there n e horter pth tht venture out of the frontier n then ome k to v. Exmple 6.. To ee where Dijktr property fil with negtive ege weight onier the following exmple Dijktr lgorithm woul viit then n leve with itne of inte of the orret itne. The prolem i tht when Dijktr viit, it fil to onier the poiility of there eing horter pth from to (whih i impoile with nonnegtive ege weight). April 9, (DRAFT, PPAP)

14 88 CHAPTER 6. SHORTEST PATHS Quetion 6.. How n we fin hortet pth on grph with negtive weight? Quetion 6.. Rell tht for Dijktr lgorithm, we trte with the rute-fore lgorithm n relize key property of hortet pth. Do you rell the property? A property we n till tke vntge of, however, i tht the u-pth of hortet pth themelve re hortet. Dijktr lgorithm took vntge of thi property y uiling longer pth from horter one, i.e., y uiling hortet pth in non-ereing orer. With negtive ege weight thi oe not work nymore, eue pth n get horter we ege. But there i nother wy to ue the me property: uiling pth tht ontin more n more ege. To ee how, uppoe tht you hve foun the hortet pth from oure to ll vertie with k or fewer ege. Quetion 6.. How n you upte the hortet pth for k + ege? Tht i you wnt to fin the hortet pth tht ontin k + or fewer ege. We n ompute the hortet pth with k + or fewer ege y extening ll pth y one ege if thi i enefiil. More peifilly, ll we nee to o i onier eh vertex v n ll it inoming ege n pik the hortet pth to tht vertex tht rrive t neighor u uing k or fewer ege n then tke the ege from u to v. To mke thi more preie, let efine δg k (, t) the hortet weighte pth from to t uing t mot k ege. April 9, (DRAFT, PPAP)

15 6.. THE BELLMAN FORD ALGORITHM 89 Exmple 6.4. In the following grph G, uppoe tht we hve foun the hortet pth from the oure to vertie uing k or fewer ege; eh vertex u i lele with it k-itne to, written δg k (, u). The weight of the hortet pth to v uing k + or fewer ege i i min δ G (, v), min δ G (, ) +, δ G (, ) + 6, δ G (, ) + The hortet pth with t mot k + ege h weight n goe through vertex v 7-7 Be on thi ie, we n ontrut pth with more n more ege. We trt y etermining δg (, v) for ll v V. Sine no vertex other thn the oure i rehle with pth of length, δg (, v) = for ll vertie other thn the oure. Then we etermine δ G (, v) for ll v V, n itertively, δ k+ G (, v) e on ll δk G (, v) for k =,.... To lulte the upte itne with t mot k + ege the lgorithm, we n ue the hortet pth with k ege to eh of it in-neighor n then in the weight of the one itionl ege. More preiely, for eh vertex v, δ k+ (v) = min(δ k (v), min x N (v) Rememer tht N (v) inite the in-neighor of vertex v. (δ k (x) + w(x, v)) ). Quetion 6.. Cn the itne for vertex ty the me? Sine the new itne for vertex i lulte in term of the itne from mot reent itertion, if the itne for ll vertie remin unhnge, then they will ontinue remining unhnge fter one more itertion. It i thu unneery to ontinue iterting fter the itne onverge. Quetion 6.6. When houl we top? We n thu top when the itne onverge. April 9, (DRAFT, PPAP)

16 9 CHAPTER 6. SHORTEST PATHS Algorithm 6.9 (Bellmn For). funtion BellmnFor(G = (V, E), ) = let % require: v V, D v = δg k (, v) 4 funtion BF(D, k) = let 6 7 in D = {v min(d[v], min u N G (v)(d[u] + w(u, v))) : v V } 8 if (k = V ) then 9 ele if (ll{d[v] = D [v] : v V }) then D ele BF (D, k + ) en D = {v if v = then ele : v V } in BF (D, ) en Quetion 6.7. I onvergene gurntee? Convergene, however i not gurntee. For exmple, if we hve negtive yle rehle from the oure then, the itne will keep getting mller n mller t eh itertion, whih i expete. Quetion 6.8. Cn we etet uh itution? We n etet negtive yle y notiing tht the itne o not onverge even fter V itertion. Thi i eue, imple (yli) pth in grph n inlue t mot V ege n, in the ene of negtive-weight yle, there lwy exit n yli hortet pth. Algorithm 6.9 efine the Bellmn For lgorithm e on thee ie. In Line 8 the lgorithm return (unefine) if there i negtive weight yle rehle from. In prtiulr ine no imple pth n e longer thn V, if the itne i till hnging fter V roun, then there mut e negtive weight yle tht w entere y the erh. An illutrtion of the lgorithm over everl tep i hown in Figure 6.. Theorem 6.4. Given irete weighte grph G = (V, E, w), w : E R, n oure, the BellmnFor lgorithm return either. δ G (, v) for ll vertie rehle from, or. if there i negtive weight-yle in the grph rehle from. April 9, (DRAFT, PPAP)

17 6.. THE BELLMAN FORD ALGORITHM pth length = pth length pth length - - pth length pth length 4 Figure 6.: Step of the Bellmn For lgorithm. The numer with qure inite wht hnge on eh tep. Proof. By inution on the numer of ege k in pth. The e e i orret ine D =. For ll v V \, on eh tep hortet (, v) pth with up to k + ege mut onit of hortet (, u) pth of up to k ege followe y ingle ege (u, v). Therefore if we tke the minimum of thee we get the overll hortet pth with up to k + ege. For the oure the elf ege will mintin D =. The lgorithm n only proee to n roun if there i rehle negtive-weight yle. Otherwie hortet pth to every v i imple n n onit of t mot n vertie n hene n ege. Cot of Bellmn-For. To nlyze the ot of Bellmn-For we onier two ifferent repreenttion for grph, one uing tle n the other uing equene. For tle-e repreenttion of the grph, we ue tle mpping eh vertex to tle of neighor long with their rel-vlue weight. We repreent the itne D tle mpping vertie to their itne. Let onier the ot of one ll to BF, not inluing the reurive ll. The only nontrivil omputtion re on Line 6 n 9. Line 6 onit of tulte over the vertie. A the ot peifition for tle inite, to lulte, the work we tke the um of the work for eh vertex, n for the pn we tke the mximum of the pn, n O(log n). Now onier wht the lgorithm oe for eh vertex. Firt, it h to fin the neighor in the grph (uing fin G v). Thi require O(log V ) work n pn. Then it involve mp over the neighor. Eh intne of thi mp require fin in the itne tle to get D[u] n n ition of the weight. The fin tke O(log V ) work n pn. Finlly there i reue tht tke O( + N G (v) ) work n O(log N G (v) ) pn. Uing April 9, (DRAFT, PPAP)

18 9 CHAPTER 6. SHORTEST PATHS n = V n m = E, the work i W = O log n + N G (v) + v V = O ((n + m) log n). ( + log n) u N G (v) Similrly, pn i ( ( )) S = O mx log n + log N G (v) + mx ( + log n) v V u N(v) = O(log n). The work n pn of Line 9 i impler to nlyze ine it only involve tulte n reution: it require O(n log n) work n O(log n) pn. Sine the numer of ll to BF i oune y n, iue erlier. Thee ll re one equentilly o we n multiply the work n pn for eh ll y the numer of ll giving: W (n, m) = O(nm log n) S(n, m) = O(n log n) Let now onier the ot with equene repreenttion of grph. If we ume the vertie re the integer {,,..., V } then we n ue equene to repreent the grph. Inte of uing fin for tle, whih require O(log n) work, we n ue nth (inexing) requiring only O() work. Thi improvement in ot n e pplie for looking up in the grph to fin the neighor of vertex, n looking up in the itne tle to fin the urrent itne. By uing the improve ot we get: W = O + N G (v) + v V u N G (v) = O(m) ( ( )) S = O mx + log N G (v) + mx v V u N(v) = O(log n) n hene the overll omplexity for BellmnFor with rry equene i: W (n, m) = O(nm) S(n, m) = O(n log n) By uing rry equene we hve reue the work y O(log n) ftor. April 9, (DRAFT, PPAP)

19 6.4. PROBLEMS Prolem Exerie 6.4. We mentione tht we re ometime only interete in the weight of hortet pth, rther thn the pth itelf. For weighte grph G = (V, E, w), ume you re given the itne δ G (, v) for ll vertie v V. For prtiulr vertex u, erie how you oul etermine the vertie P in hortet pth from to u in O(p) work, where p = v P (v). Exerie 6.4. Prove tht the u-pth property hol for ny grph, lo in the preene of negtive weight. Exerie 6.4. Argue tht if ll ege in grph hve weight then Dijktr lgorithm erie viit extly the me et of vertie in eh roun BFS oe. April 9, (DRAFT, PPAP)

20 94 CHAPTER 6. SHORTEST PATHS. April 9, (DRAFT, PPAP)

13.1 Weighted Graphs and Their Representation

13.1 Weighted Graphs and Their Representation Chpter Shortet Pth In thi hpter we will over prolem involving fining the hortet pth etween vertie in grph with weight (length) on the ege. One oviou pplition i in fining the hortet route from one re to

More information

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chpter 9 Greey Tehnique Copyright 2007 Person Aison-Wesley. All rights reserve. Greey Tehnique Construts solution to n optimiztion prolem piee y piee through sequene of hoies tht re: fesile lolly optiml

More information

10.2 Graph Terminology and Special Types of Graphs

10.2 Graph Terminology and Special Types of Graphs 10.2 Grph Terminology n Speil Types of Grphs Definition 1. Two verties u n v in n unirete grph G re lle jent (or neighors) in G iff u n v re enpoints of n ege e of G. Suh n ege e is lle inient with the

More information

V = set of vertices (vertex / node) E = set of edges (v, w) (v, w in V)

V = set of vertices (vertex / node) E = set of edges (v, w) (v, w in V) Definitions G = (V, E) V = set of verties (vertex / noe) E = set of eges (v, w) (v, w in V) (v, w) orere => irete grph (igrph) (v, w) non-orere => unirete grph igrph: w is jent to v if there is n ege from

More information

Distance vector protocol

Distance vector protocol istne vetor protool Irene Finohi finohi@i.unirom.it Routing Routing protool Gol: etermine goo pth (sequene of routers) thru network from soure to Grph strtion for routing lgorithms: grph noes re routers

More information

Greedy Algorithm. Algorithm Fall Semester

Greedy Algorithm. Algorithm Fall Semester Greey Algorithm Algorithm 0 Fll Semester Optimiztion prolems An optimiztion prolem is one in whih you wnt to fin, not just solution, ut the est solution A greey lgorithm sometimes works well for optimiztion

More information

c s ha2 c s Half Adder Figure 2: Full Adder Block Diagram

c s ha2 c s Half Adder Figure 2: Full Adder Block Diagram Adder Tk: Implement 2-it dder uing 1-it full dder nd 1-it hlf dder omponent (Figure 1) tht re onneted together in top-level module. Derie oth omponent in VHDL. Prepre two implementtion where VHDL omponent

More information

Premaster Course Algorithms 1 Chapter 6: Shortest Paths. Christian Scheideler SS 2018

Premaster Course Algorithms 1 Chapter 6: Shortest Paths. Christian Scheideler SS 2018 Premster Course Algorithms Chpter 6: Shortest Pths Christin Scheieler SS 8 Bsic Grph Algorithms Overview: Shortest pths in DAGs Dijkstr s lgorithm Bellmn-For lgorithm Johnson s metho SS 8 Chpter 6 Shortest

More information

COMMON FRACTIONS. or a / b = a b. , a is called the numerator, and b is called the denominator.

COMMON FRACTIONS. or a / b = a b. , a is called the numerator, and b is called the denominator. COMMON FRACTIONS BASIC DEFINITIONS * A frtion is n inite ivision. or / * In the frtion is lle the numertor n is lle the enomintor. * The whole is seprte into "" equl prts n we re onsiering "" of those

More information

Graph Contraction and Connectivity

Graph Contraction and Connectivity Chpter 14 Grph Contrtion n Connetivity So fr we hve mostly overe tehniques for solving problems on grphs tht were evelope in the ontext of sequentil lgorithms. Some of them re esy to prllelize while others

More information

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries Tries Yufei To KAIST April 9, 2013 Y. To, April 9, 2013 Tries In this lecture, we will discuss the following exct mtching prolem on strings. Prolem Let S e set of strings, ech of which hs unique integer

More information

Shortest Paths in Directed Graphs

Shortest Paths in Directed Graphs Shortet Path in Direted Graph Jonathan Turner January, 0 Thi note i adapted from Data Struture and Network Algorithm y Tarjan. Let G = (V, E) e a direted graph and let length e a real-valued funtion on

More information

CS 241 Week 4 Tutorial Solutions

CS 241 Week 4 Tutorial Solutions CS 4 Week 4 Tutoril Solutions Writing n Assemler, Prt & Regulr Lnguges Prt Winter 8 Assemling instrutions utomtilly. slt $d, $s, $t. Solution: $d, $s, nd $t ll fit in -it signed integers sine they re 5-it

More information

Graph theory Route problems

Graph theory Route problems Bhelors thesis Grph theory Route prolems Author: Aolphe Nikwigize Dte: 986 - -5 Sujet: Mthemtis Level: First level (Bhelor) Course oe: MAE Astrt In this thesis we will review some route prolems whih re

More information

Outline. CS38 Introduction to Algorithms. Graphs. Graphs. Graphs. Graph traversals

Outline. CS38 Introduction to Algorithms. Graphs. Graphs. Graphs. Graph traversals Outline CS38 Introution to Algorithms Leture 2 April 3, 2014 grph trversls (BFS, DFS) onnetivity topologil sort strongly onnete omponents heps n hepsort greey lgorithms April 3, 2014 CS38 Leture 2 2 Grphs

More information

5 ANGLES AND POLYGONS

5 ANGLES AND POLYGONS 5 GLES POLYGOS urling rige looks like onventionl rige when it is extene. However, it urls up to form n otgon to llow ots through. This Rolling rige is in Pington sin in Lonon, n urls up every Friy t miy.

More information

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs.

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs. Lecture 5 Wlks, Trils, Pths nd Connectedness Reding: Some of the mteril in this lecture comes from Section 1.2 of Dieter Jungnickel (2008), Grphs, Networks nd Algorithms, 3rd edition, which is ville online

More information

Calculus Differentiation

Calculus Differentiation //007 Clulus Differentition Jeffrey Seguritn person in rowot miles from the nerest point on strit shoreline wishes to reh house 6 miles frther down the shore. The person n row t rte of mi/hr nd wlk t rte

More information

Table-driven look-ahead lexical analysis

Table-driven look-ahead lexical analysis Tle-riven look-he lexil nlysis WUU YANG Computer n Informtion Siene Deprtment Ntionl Chio-Tung University, HsinChu, Tiwn, R.O.C. Astrt. Moern progrmming lnguges use regulr expressions to efine vli tokens.

More information

Section 2.3 Functions. Definition: Let A and B be sets. A function (mapping, map) f from A to B, denoted f :A B, is a subset of A B such that

Section 2.3 Functions. Definition: Let A and B be sets. A function (mapping, map) f from A to B, denoted f :A B, is a subset of A B such that Setion 2.3 Funtions Definition: Let n e sets. funtion (mpping, mp) f from to, enote f :, is suset of suh tht x[x y[y < x, y > f ]] n [< x, y 1 > f < x, y 2 > f ] y 1 = y 2 Note: f ssoites with eh x in

More information

3D convex hulls. Convex Hull in 3D. convex polyhedron. convex polyhedron. The problem: Given a set P of points in 3D, compute their convex hull

3D convex hulls. Convex Hull in 3D. convex polyhedron. convex polyhedron. The problem: Given a set P of points in 3D, compute their convex hull Convex Hull in The rolem: Given set P of oints in, omute their onvex hull onvex hulls Comuttionl Geometry [si 3250] Lur Tom Bowoin College onvex olyheron 1 2 3 olygon olyheron onvex olyheron 4 5 6 Polyheron

More information

Introduction to Algebra

Introduction to Algebra INTRODUCTORY ALGEBRA Mini-Leture 1.1 Introdution to Alger Evlute lgeri expressions y sustitution. Trnslte phrses to lgeri expressions. 1. Evlute the expressions when =, =, nd = 6. ) d) 5 10. Trnslte eh

More information

Solids. Solids. Curriculum Ready.

Solids. Solids. Curriculum Ready. Curriulum Rey www.mthletis.om This ooklet is ll out ientifying, rwing n mesuring solis n prisms. SOM CUES The Som Cue ws invente y Dnish sientist who went y the nme of Piet Hein. It is simple 3 # 3 #

More information

Lecture 13: Graphs I: Breadth First Search

Lecture 13: Graphs I: Breadth First Search Leture 13 Grphs I: BFS 6.006 Fll 2011 Leture 13: Grphs I: Bredth First Serh Leture Overview Applitions of Grph Serh Grph Representtions Bredth-First Serh Rell: Grph G = (V, E) V = set of verties (ritrry

More information

Lesson 4.4. Euler Circuits and Paths. Explore This

Lesson 4.4. Euler Circuits and Paths. Explore This Lesson 4.4 Euler Ciruits nd Pths Now tht you re fmilir with some of the onepts of grphs nd the wy grphs onvey onnetions nd reltionships, it s time to egin exploring how they n e used to model mny different

More information

MITSUBISHI ELECTRIC RESEARCH LABORATORIES Cambridge, Massachusetts. Introduction to Matroids and Applications. Srikumar Ramalingam

MITSUBISHI ELECTRIC RESEARCH LABORATORIES Cambridge, Massachusetts. Introduction to Matroids and Applications. Srikumar Ramalingam Cmrige, Msshusetts Introution to Mtrois n Applitions Srikumr Rmlingm MERL mm//yy Liner Alger (,0,0) (0,,0) Liner inepenene in vetors: v, v2,..., For ll non-trivil we hve s v s v n s, s2,..., s n 2v2...

More information

COMP108 Algorithmic Foundations

COMP108 Algorithmic Foundations Grph Theory Prudene Wong http://www.s.liv..uk/~pwong/tehing/omp108/201617 How to Mesure 4L? 3L 5L 3L ontiner & 5L ontiner (without mrk) infinite supply of wter You n pour wter from one ontiner to nother

More information

COMP 423 lecture 11 Jan. 28, 2008

COMP 423 lecture 11 Jan. 28, 2008 COMP 423 lecture 11 Jn. 28, 2008 Up to now, we hve looked t how some symols in n lphet occur more frequently thn others nd how we cn sve its y using code such tht the codewords for more frequently occuring

More information

Lecture 8: Graph-theoretic problems (again)

Lecture 8: Graph-theoretic problems (again) COMP36111: Advned Algorithms I Leture 8: Grph-theoreti prolems (gin) In Prtt-Hrtmnn Room KB2.38: emil: iprtt@s.mn..uk 2017 18 Reding for this leture: Sipser: Chpter 7. A grph is pir G = (V, E), where V

More information

Introduction. Example

Introduction. Example OMS0 Introution isjoint sets n minimum spnning trees In this leture we will strt by isussing t struture use for mintining isjoint subsets of some bigger set. This hs number of pplitions, inluing to mintining

More information

Advanced Programming Handout 5. Enter Okasaki. Persistent vs. Ephemeral. Functional Queues. Simple Example. Persistent vs.

Advanced Programming Handout 5. Enter Okasaki. Persistent vs. Ephemeral. Functional Queues. Simple Example. Persistent vs. Avne Progrmming Hnout 5 Purel Funtionl Dt Strutures: A Cse Stu in Funtionl Progrmming Persistent vs. Ephemerl An ephemerl t struture is one for whih onl one version is ville t time: fter n upte opertion,

More information

Generic Traverse. CS 362, Lecture 19. DFS and BFS. Today s Outline

Generic Traverse. CS 362, Lecture 19. DFS and BFS. Today s Outline Generic Travere CS 62, Lecture 9 Jared Saia Univerity of New Mexico Travere(){ put (nil,) in bag; while (the bag i not empty){ take ome edge (p,v) from the bag if (v i unmarked) mark v; parent(v) = p;

More information

Ma/CS 6b Class 1: Graph Recap

Ma/CS 6b Class 1: Graph Recap M/CS 6 Clss 1: Grph Recp By Adm Sheffer Course Detils Adm Sheffer. Office hour: Tuesdys 4pm. dmsh@cltech.edu TA: Victor Kstkin. Office hour: Tuesdys 7pm. 1:00 Mondy, Wednesdy, nd Fridy. http://www.mth.cltech.edu/~2014-15/2term/m006/

More information

Lecture 14: Minimum Spanning Tree I

Lecture 14: Minimum Spanning Tree I COMPSCI 0: Deign and Analyi of Algorithm October 4, 07 Lecture 4: Minimum Spanning Tree I Lecturer: Rong Ge Scribe: Fred Zhang Overview Thi lecture we finih our dicuion of the hortet path problem and introduce

More information

Computational geometry

Computational geometry Leture 23 Computtionl geometry Supplementl reding in CLRS: Chpter 33 exept 33.3 There re mny importnt prolems in whih the reltionships we wish to nlyze hve geometri struture. For exmple, omputtionl geometry

More information

Internet Routing. Reminder: Routing. CPSC Network Programming

Internet Routing. Reminder: Routing. CPSC Network Programming PS 360 - Network Progrmming Internet Routing Mihele Weigle eprtment of omputer Siene lemson University mweigle@s.lemson.eu pril, 00 http://www.s.lemson.eu/~mweigle/ourses/ps360 Reminer: Routing Internet

More information

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. Example: Pancake Problem. Example: Pancake Problem

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. Example: Pancake Problem. Example: Pancake Problem Announcements Project : erch It s live! Due 9/. trt erly nd sk questions. It s longer thn most! Need prtner? Come up fter clss or try Pizz ections: cn go to ny, ut hve priority in your own C 88: Artificil

More information

Bayesian Networks: Directed Markov Properties (Cont d) and Markov Equivalent DAGs

Bayesian Networks: Directed Markov Properties (Cont d) and Markov Equivalent DAGs Byesin Networks: Direte Mrkov Properties (Cont ) n Mrkov Equivlent DAGs Huizhen Yu jney.yu@s.helsinki.fi Dept. Computer Siene, Univ. of Helsinki Proilisti Moels, Spring, 2010 Huizhen Yu (U.H.) Byesin Networks:

More information

Cutting a Cornered Convex Polygon Out of a Circle

Cutting a Cornered Convex Polygon Out of a Circle 4 JOURNAL OF COMUTERS, VOL. 5, NO. 1, JANUARY 2010 Cutting Cornered Conve olygon Out of Cirle Syed Ihtique Ahmed, Md. Ariful Ilm nd Mud Hn Deprtment of Computer Siene nd Engineering Bngldeh Univerity of

More information

Pipeline Example: Cycle 1. Pipeline Example: Cycle 2. Pipeline Example: Cycle 4. Pipeline Example: Cycle 3. 3 instructions. 3 instructions.

Pipeline Example: Cycle 1. Pipeline Example: Cycle 2. Pipeline Example: Cycle 4. Pipeline Example: Cycle 3. 3 instructions. 3 instructions. ipeline Exmple: Cycle 1 ipeline Exmple: Cycle X X/ /W X X/ /W $3,$,$1 lw $,0($5) $3,$,$1 3 instructions 8 9 ipeline Exmple: Cycle 3 ipeline Exmple: Cycle X X/ /W X X/ /W sw $6,($7) lw $,0($5) $3,$,$1 sw

More information

1 Disjoint-set data structure.

1 Disjoint-set data structure. CS 124 Setion #4 Union-Fin, Greey Algorithms 2/20/17 1 Disjoint-set ata struture. 1.1 Operations Disjoint-set ata struture enale us to effiiently perform operations suh as plaing elements into sets, querying

More information

Class Overview. Database Design. Database Design Process. Database Design. Introduction to Data Management CSE 414

Class Overview. Database Design. Database Design Process. Database Design. Introduction to Data Management CSE 414 Introution to Dt Mngement CSE 44 Unit 6: Coneptul Design E/R Digrms Integrity Constrints BCNF Introution to Dt Mngement CSE 44 E/R Digrms ( letures) CSE 44 Autumn 08 Clss Overview Dtse Design Unit : Intro

More information

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search.

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search. CS 88: Artificil Intelligence Fll 00 Lecture : A* Serch 9//00 A* Serch rph Serch Tody Heuristic Design Dn Klein UC Berkeley Multiple slides from Sturt Russell or Andrew Moore Recp: Serch Exmple: Pncke

More information

2 Computing all Intersections of a Set of Segments Line Segment Intersection

2 Computing all Intersections of a Set of Segments Line Segment Intersection 15-451/651: Design & Anlysis of Algorithms Novemer 14, 2016 Lecture #21 Sweep-Line nd Segment Intersection lst chnged: Novemer 8, 2017 1 Preliminries The sweep-line prdigm is very powerful lgorithmic design

More information

Paradigm 5. Data Structure. Suffix trees. What is a suffix tree? Suffix tree. Simple applications. Simple applications. Algorithms

Paradigm 5. Data Structure. Suffix trees. What is a suffix tree? Suffix tree. Simple applications. Simple applications. Algorithms Prdigm. Dt Struture Known exmples: link tble, hep, Our leture: suffix tree Will involve mortize method tht will be stressed shortly in this ourse Suffix trees Wht is suffix tree? Simple pplitions History

More information

6.045J/18.400J: Automata, Computability and Complexity. Quiz 2: Solutions. Please write your name in the upper corner of each page.

6.045J/18.400J: Automata, Computability and Complexity. Quiz 2: Solutions. Please write your name in the upper corner of each page. 6045J/18400J: Automt, Computbility nd Complexity Mrh 30, 2005 Quiz 2: Solutions Prof Nny Lynh Vinod Vikuntnthn Plese write your nme in the upper orner of eh pge Problem Sore 1 2 3 4 5 6 Totl Q2-1 Problem

More information

Shortest Paths Problem. CS 362, Lecture 20. Today s Outline. Negative Weights

Shortest Paths Problem. CS 362, Lecture 20. Today s Outline. Negative Weights Shortet Path Problem CS 6, Lecture Jared Saia Univerity of New Mexico Another intereting problem for graph i that of finding hortet path Aume we are given a weighted directed graph G = (V, E) with two

More information

Typing with Weird Keyboards Notes

Typing with Weird Keyboards Notes Typing with Weird Keyords Notes Ykov Berchenko-Kogn August 25, 2012 Astrct Consider lnguge with n lphet consisting of just four letters,,,, nd. There is spelling rule tht sys tht whenever you see n next

More information

Ma/CS 6b Class 1: Graph Recap

Ma/CS 6b Class 1: Graph Recap M/CS 6 Clss 1: Grph Recp By Adm Sheffer Course Detils Instructor: Adm Sheffer. TA: Cosmin Pohot. 1pm Mondys, Wednesdys, nd Fridys. http://mth.cltech.edu/~2015-16/2term/m006/ Min ook: Introduction to Grph

More information

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards A Tutology Checker loosely relted to Stålmrck s Algorithm y Mrtin Richrds mr@cl.cm.c.uk http://www.cl.cm.c.uk/users/mr/ University Computer Lortory New Museum Site Pemroke Street Cmridge, CB2 3QG Mrtin

More information

Problem Final Exam Set 2 Solutions

Problem Final Exam Set 2 Solutions CSE 5 5 Algoritms nd nd Progrms Prolem Finl Exm Set Solutions Jontn Turner Exm - //05 0/8/0. (5 points) Suppose you re implementing grp lgoritm tt uses ep s one of its primry dt strutures. Te lgoritm does

More information

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

In the last lecture, we discussed how valid tokens may be specified by regular expressions. LECTURE 5 Scnning SYNTAX ANALYSIS We know from our previous lectures tht the process of verifying the syntx of the progrm is performed in two stges: Scnning: Identifying nd verifying tokens in progrm.

More information

Outline. Motivation Background ARCH. Experiment Additional usages for Input-Depth. Regular Expression Matching DPI over Compressed HTTP

Outline. Motivation Background ARCH. Experiment Additional usages for Input-Depth. Regular Expression Matching DPI over Compressed HTTP ARCH This work ws supported y: The Europen Reserh Counil, The Isreli Centers of Reserh Exellene, The Neptune Consortium, nd Ntionl Siene Foundtion wrd CNS-119748 Outline Motivtion Bkground Regulr Expression

More information

Today s Outline. CS 561, Lecture 23. Negative Weights. Shortest Paths Problem. The presence of a negative cycle might mean that there is

Today s Outline. CS 561, Lecture 23. Negative Weights. Shortest Paths Problem. The presence of a negative cycle might mean that there is Today Outline CS 56, Lecture Jared Saia Univerity of New Mexico The path that can be trodden i not the enduring and unchanging Path. The name that can be named i not the enduring and unchanging Name. -

More information

Containers: Queue and List

Containers: Queue and List Continers: Queue n List Queue A ontiner in whih insertion is one t one en (the til) n eletion is one t the other en (the he). Also lle FIFO (First-In, First-Out) Jori Cortell n Jori Petit Deprtment of

More information

Describing Combinational circuits in BSV

Describing Combinational circuits in BSV Decriing Comintionl circuit in BSV Arvind Computer Science & Artificil Intelligence L. Mchuett Intitute of Technology Ferury 13, 2018 http://cg.cil.mit.edu/6.s084 L03-1 Three imple comintionl circuit NOT

More information

Distance-Vector Algorithms for Distributed Shortest Paths on Dynamic Power-Law Networks

Distance-Vector Algorithms for Distributed Shortest Paths on Dynamic Power-Law Networks Article Ditnce-Vector Algorithm for Ditriuted Shortet Pth on Dynmic Power-Lw Network Mtti D Emidio 1, * nd Dniele Frigioni 2, * 1 Grn So Science Intitute (GSSI), Vile Frnceco Cripi, I 67100 L Aquil, Itly

More information

Convex Hull Algorithms. Convex hull: basic facts

Convex Hull Algorithms. Convex hull: basic facts CG Leture D Conve Hull Algorithms Bsi fts Algorithms: Nïve, Gift wrpping, Grhm sn, Quik hull, Divide-nd-onquer Lower ound 3D Bsi fts Algorithms: Gift wrpping, Divide nd onquer, inrementl Conve hulls in

More information

Width and Bounding Box of Imprecise Points

Width and Bounding Box of Imprecise Points Width nd Bounding Box of Impreise Points Vhideh Keikh Mrten Löffler Ali Mohdes Zhed Rhmti Astrt In this pper we study the following prolem: we re given set L = {l 1,..., l n } of prllel line segments,

More information

Adjacency. Adjacency Two vertices u and v are adjacent if there is an edge connecting them. This is sometimes written as u v.

Adjacency. Adjacency Two vertices u and v are adjacent if there is an edge connecting them. This is sometimes written as u v. Terminology Adjeny Adjeny Two verties u nd v re djent if there is n edge onneting them. This is sometimes written s u v. v v is djent to nd ut not to. 2 / 27 Neighourhood Neighourhood The open neighourhood

More information

CSCI 104. Rafael Ferreira da Silva. Slides adapted from: Mark Redekopp and David Kempe

CSCI 104. Rafael Ferreira da Silva. Slides adapted from: Mark Redekopp and David Kempe CSCI 0 fel Ferreir d Silv rfsilv@isi.edu Slides dpted from: Mrk edekopp nd Dvid Kempe LOG STUCTUED MEGE TEES Series Summtion eview Let n = + + + + k $ = #%& #. Wht is n? n = k+ - Wht is log () + log ()

More information

Duality in linear interval equations

Duality in linear interval equations Aville online t http://ijim.sriu..ir Int. J. Industril Mthemtis Vol. 1, No. 1 (2009) 41-45 Dulity in liner intervl equtions M. Movhedin, S. Slhshour, S. Hji Ghsemi, S. Khezerloo, M. Khezerloo, S. M. Khorsny

More information

What are suffix trees?

What are suffix trees? Suffix Trees 1 Wht re suffix trees? Allow lgorithm designers to store very lrge mount of informtion out strings while still keeping within liner spce Allow users to serch for new strings in the originl

More information

Pattern Matching. Pattern Matching. Pattern Matching. Review of Regular Expressions

Pattern Matching. Pattern Matching. Pattern Matching. Review of Regular Expressions Pttern Mthing Pttern Mthing Some of these leture slides hve een dpted from: lgorithms in C, Roert Sedgewik. Gol. Generlize string serhing to inompletely speified ptterns. pplitions. Test if string or its

More information

10.5 Graphing Quadratic Functions

10.5 Graphing Quadratic Functions 0.5 Grphing Qudrtic Functions Now tht we cn solve qudrtic equtions, we wnt to lern how to grph the function ssocited with the qudrtic eqution. We cll this the qudrtic function. Grphs of Qudrtic Functions

More information

WORKSHOP 9 HEX MESH USING SWEEP VECTOR

WORKSHOP 9 HEX MESH USING SWEEP VECTOR WORKSHOP 9 HEX MESH USING SWEEP VECTOR WS9-1 WS9-2 Prolem Desription This exerise involves importing urve geometry from n IGES file. The urves re use to rete other urves. From the urves trimme surfes re

More information

Lecture 17: Shortest Paths

Lecture 17: Shortest Paths Lecture 7: Shortet Path CSE 373: Data Structure and Algorithm CSE 373 9 WI - KASEY CHAMPION Adminitrivia How to Ace the Technical Interview Seion today! - 6-8pm - Sieg 34 No BS CS Career Talk Thurday -

More information

Lecture 18 Graph-Based Algorithms. CSE373: Design and Analysis of Algorithms

Lecture 18 Graph-Based Algorithms. CSE373: Design and Analysis of Algorithms Lecture 18 Graph-Baed Algorithm CSE: Deign and Anali of Algorithm Shortet Path Problem Modeling problem a graph problem: Road map i a weighted graph: vertice = citie edge = road egment between citie edge

More information

Uninformed Search Complexity. Informed Search. Search Revisited. Day 2/3 of Search

Uninformed Search Complexity. Informed Search. Search Revisited. Day 2/3 of Search Informed Search ay 2/3 of Search hap. 4, Ruel & Norvig FS IFS US PFS MEM FS IS Uninformed Search omplexity N = Total number of tate = verage number of ucceor (branching factor) L = Length for tart to goal

More information

Final Exam Review F 06 M 236 Be sure to look over all of your tests, as well as over the activities you did in the activity book

Final Exam Review F 06 M 236 Be sure to look over all of your tests, as well as over the activities you did in the activity book inl xm Review 06 M 236 e sure to loo over ll of your tests, s well s over the tivities you did in the tivity oo 1 1. ind the mesures of the numered ngles nd justify your wor. Line j is prllel to line.

More information

Contents. shortest paths. Notation. Shortest path problem. Applications. Algorithms and Networks 2010/2011. In the entire course:

Contents. shortest paths. Notation. Shortest path problem. Applications. Algorithms and Networks 2010/2011. In the entire course: Content Shortet path Algorithm and Network 21/211 The hortet path problem: Statement Verion Application Algorithm (for ingle ource p problem) Reminder: relaxation, Dijktra, Variant of Dijktra, Bellman-Ford,

More information

Internet Routing. IP Packet Format. IP Fragmentation & Reassembly. Principles of Internet Routing. Computer Networks 9/29/2014.

Internet Routing. IP Packet Format. IP Fragmentation & Reassembly. Principles of Internet Routing. Computer Networks 9/29/2014. omputer Networks 9/29/2014 IP Pket Formt Internet Routing Ki Shen IP protool version numer heder length (words) for qulity of servie mx numer remining hops (deremented t eh router) upper lyer protool to

More information

Giving credit where credit is due

Giving credit where credit is due JEP 84H Foundtion of omputer tem Proceor rchitecture II: ogic eign r. teve Goddrd goddrd@ce.unl.edu Giving credit where credit i due Mot of lide for thi lecture re ed on lide creted r. rnt, rnegie Mellon

More information

CS 151. Graph Algorithms. Wednesday, November 28, 12

CS 151. Graph Algorithms. Wednesday, November 28, 12 CS 151 Graph Algorithm 1 Unweighted Shortet Path Problem input: a graph G=(V,E) and a tart vertex goal: determine the length of the hortet path from to every vertex in V (and while you re at it, compute

More information

CMPUT101 Introduction to Computing - Summer 2002

CMPUT101 Introduction to Computing - Summer 2002 CMPUT Introdution to Computing - Summer 22 %XLOGLQJ&RPSXWHU&LUFXLWV Chpter 4.4 3XUSRVH We hve looked t so fr how to uild logi gtes from trnsistors. Next we will look t how to uild iruits from logi gtes,

More information

Chapter 4 Fuzzy Graph and Relation

Chapter 4 Fuzzy Graph and Relation Chpter 4 Fuzzy Grph nd Reltion Grph nd Fuzzy Grph! Grph n G = (V, E) n V : Set of verties(node or element) n E : Set of edges An edge is pir (x, y) of verties in V.! Fuzzy Grph ~ n ( ~ G = V, E) n V :

More information

12/9/14. CS151 Fall 20124Lecture (almost there) 12/6. Graphs. Seven Bridges of Königsberg. Leonard Euler

12/9/14. CS151 Fall 20124Lecture (almost there) 12/6. Graphs. Seven Bridges of Königsberg. Leonard Euler CS5 Fll 04Leture (lmost there) /6 Seven Bridges of Königserg Grphs Prof. Tny Berger-Wolf Leonrd Euler 707-783 Is it possile to wlk with route tht rosses eh ridge e Seven Bridges of Königserg Forget unimportnt

More information

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string. CS 340, Fll 2016 Sep 29th Exm 1 Nme: Note: in ll questions, the speil symol ɛ (epsilon) is used to indite the empty string. Question 1. [10 points] Speify regulr expression tht genertes the lnguge over

More information

AI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley

AI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley AI Adjcent Fields Philosophy: Logic, methods of resoning Mind s physicl system Foundtions of lerning, lnguge, rtionlity Mthemtics Forml representtion nd proof Algorithms, computtion, (un)decidility, (in)trctility

More information

Error Numbers of the Standard Function Block

Error Numbers of the Standard Function Block A.2.2 Numers of the Stndrd Funtion Blok evlution The result of the logi opertion RLO is set if n error ours while the stndrd funtion lok is eing proessed. This llows you to rnh to your own error evlution

More information

Today s Outline. CS 362, Lecture 19. DFS and BFS. Generic Traverse. BFS and DFS Wrapup Shortest Paths. Jared Saia University of New Mexico

Today s Outline. CS 362, Lecture 19. DFS and BFS. Generic Traverse. BFS and DFS Wrapup Shortest Paths. Jared Saia University of New Mexico Today Outline CS 362, Lecture 9 Jared Saia Univerity of New Mexico BFS and DFS Wrapup Shortet Path Generic Travere DFS and BFS Travere(){ put (nil,) in bag; while (the bag i not empty){ take ome edge (p,v)

More information

F. R. K. Chung y. University ofpennsylvania. Philadelphia, Pennsylvania R. L. Graham. AT&T Labs - Research. March 2,1997.

F. R. K. Chung y. University ofpennsylvania. Philadelphia, Pennsylvania R. L. Graham. AT&T Labs - Research. March 2,1997. Forced convex n-gons in the plne F. R. K. Chung y University ofpennsylvni Phildelphi, Pennsylvni 19104 R. L. Grhm AT&T Ls - Reserch Murry Hill, New Jersey 07974 Mrch 2,1997 Astrct In seminl pper from 1935,

More information

The Fundamental Theorem of Calculus

The Fundamental Theorem of Calculus MATH 6 The Fundmentl Theorem of Clculus The Fundmentl Theorem of Clculus (FTC) gives method of finding the signed re etween the grph of f nd the x-xis on the intervl [, ]. The theorem is: FTC: If f is

More information

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016 Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence Winter 2016 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl

More information

Asurveyofpractical algorithms for suffix tree construction in external memory

Asurveyofpractical algorithms for suffix tree construction in external memory Asurveyofprtil lgorithms for suffix tree onstrution in externl memory M. Brsky,, U. Stege n A. Thomo University of Vitori, PO Box, STN CSC Vitori, BC, VW P, Cn SUMMAY The onstrution of suffix trees in

More information

Lecture 12 : Topological Spaces

Lecture 12 : Topological Spaces Leture 12 : Topologil Spes 1 Topologil Spes Topology generlizes notion of distne nd loseness et. Definition 1.1. A topology on set X is olletion T of susets of X hving the following properties. 1. nd X

More information

Today. Search Problems. Uninformed Search Methods. Depth-First Search Breadth-First Search Uniform-Cost Search

Today. Search Problems. Uninformed Search Methods. Depth-First Search Breadth-First Search Uniform-Cost Search Uninformed Serch [These slides were creted by Dn Klein nd Pieter Abbeel for CS188 Intro to AI t UC Berkeley. All CS188 mterils re vilble t http://i.berkeley.edu.] Tody Serch Problems Uninformed Serch Methods

More information

PROBLEM OF APOLLONIUS

PROBLEM OF APOLLONIUS PROBLEM OF APOLLONIUS In the Jnury 010 issue of Amerin Sientist D. Mkenzie isusses the Apollonin Gsket whih involves fining the rius of the lrgest irle whih just fits into the spe etween three tngent irles

More information

Shortest Path Problems

Shortest Path Problems Shortet Path Problem How can we find the hortet route between two point on a road map? Model the problem a a graph problem: Road map i a weighted graph: vertice = citie edge = road egment between citie

More information

Comparing Hierarchical Data in External Memory

Comparing Hierarchical Data in External Memory Compring Hierrhil Dt in Externl Memory Surshn S. Chwthe Deprtment of Computer Siene University of Mryln College Prk, MD 090 hw@s.um.eu Astrt We present n externl-memory lgorithm for omputing minimum-ost

More information

Network Layer: Routing Classifications; Shortest Path Routing

Network Layer: Routing Classifications; Shortest Path Routing igitl ommuniction in the Modern World : Routing lssifictions; Shortest Pth Routing s min prolem: To get efficiently from one point to the other in dynmic environment http://.cs.huji.c.il/~com com@cs.huji.c.il

More information

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork MA1008 Clculus nd Liner Algebr for Engineers Course Notes for Section B Stephen Wills Deprtment of Mthemtics University College Cork s.wills@ucc.ie http://euclid.ucc.ie/pges/stff/wills/teching/m1008/ma1008.html

More information

Hyperbolas. Definition of Hyperbola

Hyperbolas. Definition of Hyperbola CHAT Pre-Clculus Hyperols The third type of conic is clled hyperol. For n ellipse, the sum of the distnces from the foci nd point on the ellipse is fixed numer. For hyperol, the difference of the distnces

More information

Minimum congestion spanning trees in bipartite and random graphs

Minimum congestion spanning trees in bipartite and random graphs Minimum congetion panning tree in bipartite and random graph M.I. Otrovkii Department of Mathematic and Computer Science St. John Univerity 8000 Utopia Parkway Queen, NY 11439, USA e-mail: otrovm@tjohn.edu

More information

Honors Thesis: Investigating the Algebraic Properties of Cayley Digraphs

Honors Thesis: Investigating the Algebraic Properties of Cayley Digraphs Honors Thesis: Investigting the Algebri Properties of Cyley Digrphs Alexis Byers, Wittenberg University Mthemtis Deprtment April 30, 2014 This pper utilizes Grph Theory to gin insight into the lgebri struture

More information

MTH 146 Conics Supplement

MTH 146 Conics Supplement 105- Review of Conics MTH 146 Conics Supplement In this section we review conics If ou ne more detils thn re present in the notes, r through section 105 of the ook Definition: A prol is the set of points

More information

Suffix trees, suffix arrays, BWT

Suffix trees, suffix arrays, BWT ALGORITHMES POUR LA BIO-INFORMATIQUE ET LA VISUALISATION COURS 3 Rluc Uricru Suffix trees, suffix rrys, BWT Bsed on: Suffix trees nd suffix rrys presenttion y Him Kpln Suffix trees course y Pco Gomez Liner-Time

More information

MATH 25 CLASS 5 NOTES, SEP

MATH 25 CLASS 5 NOTES, SEP MATH 25 CLASS 5 NOTES, SEP 30 2011 Contents 1. A brief diversion: reltively prime numbers 1 2. Lest common multiples 3 3. Finding ll solutions to x + by = c 4 Quick links to definitions/theorems Euclid

More information

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy Recognition of Tokens if expressions nd reltionl opertors if è if then è then else è else relop

More information

Grade 7/8 Math Circles Geometric Arithmetic October 31, 2012

Grade 7/8 Math Circles Geometric Arithmetic October 31, 2012 Fculty of Mthemtics Wterloo, Ontrio N2L 3G1 Grde 7/8 Mth Circles Geometric Arithmetic Octoer 31, 2012 Centre for Eduction in Mthemtics nd Computing Ancient Greece hs given irth to some of the most importnt

More information