Exampls an applications on SSSP an MST Dan (Doris) H & Junhao Gan ITEE Univrsity of Qunslan COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Dijkstra s Algorithm Th algorithm solvs th singl-sourc shortst-paths (SSSP) problm on a irct graph G = (V, E) with positiv g wights. Lt V V b th currnt st of vrtics whos shortst paths from th sourc vrtx s hav bn foun an S = V \V. Th crucial part of th algorithm is th g rlaxation ia. Essntially, it is to maintain, for ach v S, th currnt shortst istanc from s only through th vrtics in V. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Suppos that th sourc vrtx is a. vrtx v ist(v) parnt(v) a 0 nil b nil c nil nil nil f nil g nil h nil V = an S = {a, b, c,,, f, g, h, i}. i nil Sinc ist(a) is th smallst among thos of vrtics in S, pick a. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of a: vrtx v ist(v) parnt(v) a 0 nil b 2 nil a c nil nil nil f nil g nil h nil V = {a} an S = {b, c,,, f, g, h, i}. i nil Th currnt shortst istanc of b from a only through th vrtics in V is upat. Aftr thn, ist(b) is th smallst among thos of vrtics in S. Pick b. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of b: vrtx v ist(v) parnt(v) a 0 nil b 2 a c nil 5 nil b nil f nil g nil h nil V = {a, b} an S = {c,,, f, g, h, i}. i nil Similarly, upat th currnt shortst istanc of from a only through th vrtics in V. An ist() is th smallst among thos in S. Pick. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of : vrtx v ist(v) parnt(v) a 0 nil b 2 a c 12 nil 5 b 6 nil f nil g nil h nil V = {a, b, } an S = {c,, f, g, h, i}. i nil Sinc aftr th upats, ist() is th smallst among thos in S, pick. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of : V = {a, b,, } an S = {c, f, g, h, i}. vrtx v ist(v) parnt(v) a 0 nil b 2 a c 12 5 b 6 f 7 nil g nil h nil i nil COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of f : V = {a, b,,, f } an S = {c, g, h, i}. vrtx v ist(v) parnt(v) a 0 nil b 2 a c 12 10 f 5 b 6 f 7 g nil h 11 nil f i nil COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of c: V = {a, b, c,,, f } an S = {g, h, i}. vrtx v ist(v) parnt(v) a 0 nil b 2 a c 10 f 5 b 6 f 7 g nil h 11 f i nil COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of h: V = {a, b, c,,, f, h} an S = {g, i}. vrtx v ist(v) parnt(v) a 0 nil b 2 a c 10 f 5 b 6 f 7 g 12 nil h h 11 f i 15 nil h COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of g: V = {a, b, c,,, f, g, h} an S = {i}. vrtx v ist(v) parnt(v) a 0 nil b 2 a c 10 f 5 b 6 f 7 g 12 h h 11 f i 15 14 h g COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Rlax th out-going gs of i: V = {a, b, c,,, f, g, h, i} an S = {}. Don. vrtx v ist(v) parnt(v) a 0 nil b 2 a c 10 f 5 b 6 f 7 g 12 h h 11 f i 14 g COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Prim s Algorithm Th algorithm grows a tr T mst by incluing on vrtx at a tim. At any momnt, it ivis th vrtx st V into two parts: Th st S of vrtics that ar alray in T mst. Th st of othr vrtics: V \S At th n of th algorithm, S = V. If an g conncts a vrtx in V an a vrtx in V \S, w call it an xtnsion g. At all tims, th algorithm nforcs th following lightst xtnsion principl: For vry vrtx v V \S, it rmmbrs which xtnsion g of v has th smallst wight rfrr to as th lightst xtnsion g of v, an not as bst-xt(v). COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Eg {a, c} is th lightst of all. S = {a, c}. Th MST has on g {a, c}. vrtx v bst-xt(v) an wight a b {b, a}, 4 c {, c}, 2 nil, f {f, c}, 10 g nil, h nil, i nil, COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Eg {, c} is th lightst of all. S = {a, c, }. A g {, c} into th MST. vrtx v bst-xt(v) an wight a b {b, a}, 4 c {, }, 3 f {f, c}, 10 g {g, }, 6 h nil, i nil, COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Eg {, } is th lightst of all. S = {a, c,, }. A g {, } into th MST. vrtx v bst-xt(v) an wight a b {b, a}, 4 c f {f, }, 5 g {g, }, 6 h nil, i nil, COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Eg {b, a} is th lightst of all. S = {a, c,,, b}. A g {b, a} into th MST. vrtx v bst-xt(v) an wight a b c f {f, }, 5 g {g, }, 6 h nil, i nil, COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Eg {f, } is th lightst of all. S = {a, c,,, b, f }. A g {f, } into th MST. vrtx v bst-xt(v) an wight a b c f g {g, }, 6 h {h, f }, 12 i nil, COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Eg {g, } is th lightst of all. S = {a, c,,, b, f, g}. A g {g, } into th MST. vrtx v bst-xt(v) an wight a b c f g h {h, f }, 12 i {i, g}, 8 COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Eg {i, g} is th lightst of all. S = {a, c,,, b, f, g, i}. A g {i, g} into th MST. vrtx v bst-xt(v) an wight a b c f g h {h, i}, 3 i COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl At th n, g {h, i} is th lightst of all. S = {a, c,,, b, f, g, i, h}. A g {h, i} into th MST an w gt th final MST. vrtx v bst-xt(v) an wight a b c f g h i COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Facility Allocation Application of Dijkstra s Algorithm Lt G = (V, E) b an unirct graph with positiv g wights, whr ach vrtx v V rprsnts ithr a usr or a facility. For a usr u an a facility f, th istanc btwn u an f is th shortst istanc from u to f on G not by ist(u, f ). Our goal is to assign th narst facility f to ach usr u such that: Thr is no facility f f such that ist(f, u) < ist(f, u). Furthrmor, w say f = narst-fac(u). COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl Givn a graph blow, f i (for i [1, 4]) rprsnts a facility an u j (for j [1, 4]) rprsnts a usr. u 1 Thn w hav: narst-fac(u 1 ) = f 2, narst-fac(u 2 ) = f 3, narst-fac(u 3 ) = f 1, narst-fac(u 4 ) = f 1. 5 8 f 2 7 2 4 10 u 4 9 6 f 1 u 3 3 8 7 f 4 10 f 3 1 2 u 2 COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Facility Allocation Application of Dijkstra s Algorithm To solv th problm, th most trivial way is to run on Dijkstra s algorithm for ach facility. An thn, for ach usr u, pick th facility f with ist(f, u) smallst. Howvr, w can o much bttr. In fact, only on Dijkstra is nough! COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Facility Allocation Application of Dijkstra s Algorithm Th algorithm is as follows: A an auxilary vrtx s to G. Crat an g {s, f } for ach facility f with g wight α, whr α > 0 is smallr than any g wight in G. Prform Dijkstra s algorithm with sourc vrtx s on th augmnt graph. In th rsult SSSP tr, for ach facility f, assign f to ach usr in th subtr of f. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl 0.5 s s u 1 5 8 f 2 7 2 4 10 u 4 9 6 f 1 u 3 3 8 7 0.5 f 4 2 10 1 f 3 u 2 0.5 0.5 f 1 f 2 f 3 f 4 u 3 u 4 u 1 u 2 COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Corrctnss Th corrctnss of th algorithm follows th facts blow: All th nos at lvl-1 (assum s is at lvl-0) in th SSSP tr ar th facility vrtics. All th usr nos u in th subtr of a facility f satisfy: ist(f, u) ist(f, u) for all facilitis f f. A short proof for th scon bullt: Suppos that thr os xist a facility f such that ist(f, u) < ist(f, u). Thn th path from s to u through f is shortr than that through f. It contraicts with th fact that u is in th subtr of f in th SSSP tr. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Travling Salsman Application of MST Givn a wight unirct graph G = (V, E) satisfying th followings: G is complt: for u, v V, {u, v} is in E. Th wight of ach g is positiv. All th wights satisfy th triangl inquality: w(u, v) w(u, x) + w(x, v) for u, v, x V, whr w(u, v) is th wight of g {u, v}. Th Travling Salsman Problm (TSP) is to fin a rout H such that: H is a cycl. Each vrtx v V is visit by H onc an xactly onc. Th total wight of th gs on H is smallst. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Exampl a a b f g b f g c h c h For simpl illustration, w show th input graph on th lft without rawing all th gs xplicitly. Insta, w mb th graph on th plan such that th wight of ach g is th uclian istanc btwn its two n points. Th r cycl shown on th right is th optimal solution H. Th TSP problm is NP-har! COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Travling Salsman Application of MST For a cycl H in th input graph, not th total wight of gs on H by w(h). In th following, w will introuc a 2-approximat algorithm for th TSP problm in th sns that it always fins a solution H with w(h) 2 w(h ), whr H is th optimal solution. COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Comput an MST T of G. Prform DFS on T from an arbitrary no an rcor th no visiting squnc S: a, b, c, b, h, b, a,,, f,, g,,, a. Only kp th first occurrnc of ach vrtx in th squnc S: a, b, c, h,,, f, g. c a b a h f g Lt H b th rout of this first occurrnc squnc. Rturn H as an approximat solution. c b h f g W claim that w(h) 2 w(h ). COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST
Proof sktch: Sinc H is a cycl on all th vrtics, rmoving any g from H will rsult to a spanning tr T. As all th g wights ar positiv an T is an MST, w hav w(t ) w(t ) < w(h ). Sinc th DFS travrss ach g of T only twic, th total wight of all th gs on th visit squnc S, not by w(s), is 2 w(t ). Consir any two conscutiv vrtics u an v on H. By th triangl inquality, w know that w(u, v) is no mor than th total wight of all th gs on th sub-squnc of S btwn thir first occurrnc. Thrfor, w(h) w(s) = 2 w(t ) < 2 w(h ). COMP3506/7505, Uni of Qunslan Exampls an applications on SSSP an MST