Single Single- -Source Shortest Paths Source Shortest Paths Single Single- -Source Shortest Paths Problem: Source Shortest Paths Problem: Given a Given a weighted graph ((G=( ((G=(V,E),w V,E),w), ), find a shortest path find a shortest path weighted graph ∈ Def. Def. Given a weighted directed graph Given a weighted directed graph ( (G(V,E),w G(V,E),w) ), we , we from a given source vertex to each vertex from a given source vertex to each vertex s V define the weight weight of of a a path path ∈ define the v V = … p v v , , , v 0 1 k as the sum of the weights of it’ as the sum of the weights of it ’s constituent edges, s constituent edges, Other variants 0f this problem Other variants 0f this problem i.e., as i.e., as = ∑ k w ( p ) w v ( , v ) − i 1 i • Single • Single- -destination shortest destination shortest- -paths problem: paths problem: Find a Find a = i 1 shortest path to a given destination shortest path to a given destination t t for each for each δ vertex v vertex v. . We define the We define the shortest shortest- -path path weight weight of of ( , ) u v from from u u to to v v as as • Single • Single- -pair shortest pair shortest- -path problem: path problem: For given For given { { } } → → ∃ ∃ p min w p ( ) : u v if a path from u to v vertices u vertices u and and v v, find a shortest path from , find a shortest path from u u to to v v δ = ∞ ( , ) u v otherwise • • All All- -pairs shortest pairs shortest- -paths problem: paths problem: For all pairs of For all pairs of vertices vertices ( (u,v u,v) ), find a shortest path from , find a shortest path from u u to to v v. . A shortest A shortest path path is one of shortest path weight. is one of shortest path weight. Optimal Substructure Optimal Substructure Single Single- -Source Shortest Paths Source Shortest Paths Lemma 24.1(Page 582). Given a weighted directed Lemma 24.1(Page 582). Given a weighted directed = … graph (G=( graph (G=(V,E),w V,E),w) ). Let be a . Let be a p v v , , , v 1 2 k shortest path from v shortest path from v 1 1 to to v v k k , then for every , then for every i,j i,j s.t s.t. . ≤ ≤ ≤ ≤ ≤ , the subpath , the subpath = is is … 1 i j k p v , , v ij i j a shortest path from a shortest path from v v i i to to v v j j . . Proof: Proof: → → p → → p → p v v ij v jk v 1 i A shortest path exists A shortest path exists iff iff there are no there are no 1 i j k reachable negative cycles. Each node v v reachable negative cycles. Each node contains a field d[v contains a field d[v] ] which is an upper bound which is an upper bound of of δ δ (s,v (s,v) ) Single- Single -Source Shortest Paths Source Shortest Paths Shortest Path Representation Shortest Path Representation ∈ For each vertex , we maintain a For each vertex v V , we maintain a [ ] [ ] π predecessor predecessor that is either a vertex or that is either a vertex or v NIL. The algorithms given in this chapter will . The algorithms given in this chapter will NIL [ ] [ ] [ ] [ ] set the predecessor so that points set the predecessor so that points π π v v to the previous vertex on the shortest path from to the previous vertex on the shortest path from source source s s to to v v. In this way, the shortest path is . In this way, the shortest path is represented. represented. We thus have a predecessor We thus have a predecessor subgraph subgraph ( ( ) ) = G V , E π π π π π where { } { } where [ ] [ ] = = ∈ ∈ π ≠ ∪ V v V : v NIL s The shortest path is not unique. π The shortest path is not unique. { } ( ( [ ] [ ] ) ) { } = = π ∈ ∈ ∈ − E v v , E v V : s π π π π 1
Shortest Path Tree Shortest Path Tree Relaxation Relaxation The algorithms we will consider will compute The algorithms we will consider will compute a shortest path tree a shortest path tree ( ( ) ) = G V , E π π π π π where where { } { } [ ] [ ] = = ∈ ∈ π ≠ ∪ V v V : v NIL s π { ( ( ) ) } [ ] [ ] { } = = π ∈ ∈ ∈ − E v v , E v V : s π π π π Properties Properties Two Single- Two Single -Source Shortest Paths Source Shortest Paths • • Bellman Bellman- -Ford Ford – – A dynamic programming A dynamic programming alg alg • • Dijkstra Dijkstra – – A greedy algorithm which works A greedy algorithm which works only when weight function is only when weight function is non non- -negative negative Bellman- Bellman -Ford Algorithm Ford Algorithm Single- -Source Shortest Paths in Source Shortest Paths in DAGs DAGs Single 2
Single- Single -Source Shortest Paths in Source Shortest Paths in DAGs DAGs Dijkstra Dijkstra’ ’s s Algorithm Algorithm Dijkstra Dijkstra’ ’s s Algorithm Algorithm Dijkstra Dijkstra’ ’s s Algorithm Algorithm Linear System of Difference Constraints Weighted Directed Graph Weighted Directed Graph Linear System of Difference Constraints Associated with a Linear System of Associated with a Linear System of Difference Constraints Difference Constraints ↔ ↔ ∈ ∈ x v V i i ( ( ) ) − − ≤ ≤ ↔ x x b edge v v , of weight b j i k i j k We add an additional vertex , and the ≥ We add an additional vertex , and the v Lemma. Let be a linear system of Lemma. Let be a linear system of Ax b 0 ( ( ) ) edges ∀ edges difference constraints. Then, if x=a x=a is a is a difference constraints. Then, if v v 0 , x i i solution, then so is a solution, then so is a +λ ,1 , ,… …,1) ,1) for every real for every real +λ(1 +λ +λ(1 (1,1 (1,1 ,1 . λ . λ 3
Weighted Directed Graph Associated with a Weighted Directed Graph Associated with a Linear System of Difference Constraints Linear System of Difference Constraints 4
Recommend
More recommend