Download presentation

Presentation is loading. Please wait.

Published byElian Madren Modified over 2 years ago

1
2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation 3.The Bellman-Ford Algorithm 4.Single-Source Shortest Paths in Directed Acyclic Graphs

2
2004 SDU 2 Shortest Paths—Notions Related 1.Given a weighted, directed graph G = (V, E; w), the weight of path p = is the sum of the weights of its constituent edges, that is, 2.Define the shortest-path weight from u to v by 3.A shortest path from vertex u to v is any path p with weight w(p) = (u, v).

3
2004 SDU 3 Single-source shortest-paths problem Input: A weighted directed graph G=(V, E, w), and a source vertex s. Output: Shortest-path weight from s to each vertex v in V, and a shortest path from s to each vertex v in V if v is reachable from s.

4
2004 SDU 4 Notes on Shortest-Paths For single-source shortest-paths problem Negative-weight edge and Negative-weight cycle reachable from s Cycles Can a shortest path contain a cycle?

5
2004 SDU 5 Representing Shortest-Paths Given a graph G = (V, E), maintain for each vertex v V a predecessor [v] that is either another vertex or NIL. Given a vertex v for which [v] NIL, the procedure PRINT-PATH(G, s, v) prints a shortest path from s to v.

6
2004 SDU 6 Property of Shortest Paths Lemma 24.1 (Sub-paths of shortest paths are shortest paths) Given a weighted, directed graph G = (V, E; w), let p = be a shortest path from vertex v 1 to vertex v k and, for any i and j such that 1 i j k, let p ij = be the sub-path of p from vertex v i to vertex v j. Then, p ij is a shortest path from v i to v j. Why?

7
2004 SDU 7 Relaxation Relaxation: In our shortest-paths problem, we maintain an attribute d[v], which is a shortest-path estimate from source s to v. The term RELAXATION is used here for an operation that tightens d[v], or the difference of d[v] and (s, v).

8
2004 SDU 8 Relaxation--Initialization The initial estimate of (s, v) can be given by:

9
2004 SDU 9 Relaxation Process Relaxing an edge (u, v) consists: Testing whether we can improve the shortest path to v found so far by going through u, and if so, Updating d[v] and [v]. A relaxation step may either decrease the value of the shortest-path estimate d[v] and update v’s predecessor [v], or cause no change.

10
2004 SDU 10 A Relaxation Step

11
2004 SDU 11 Relaxation Note: 1.All algorithms in this chapter call INITIALIZE- SINGLE-SOURCE and then repeatedly relax edges 2.Relaxation is the only means by which shortest-path estimates and predecessors change 3.The algorithms differ in how many times they relax each edge and the order in which they relax edges 4.Bellman-Ford relaxes each edge many times, while Dijkstra’s and the algorithm for directed acyclic graphs relax each edge exactly once.

12
2004 SDU 12 Properties of Shortest Paths and Relaxation Suppose we have already initialized d[] and [], and the only way used to change their values is relaxation. Triangle inequality (Lemma 24.10) For any edge (u, v) E, we have (s, v) (s, u) + w(u, v) Upper-bound property (Lemma 24.11) We always have d[v] (s, v) for all vertices v V, and once d[v] achieves the value (s, v), it never changes. No-path property (Lemma 24.12) If there is no path from s to v, then we always have d[v] = (s, v) = .

13
2004 SDU 13 Properties of Shortest Paths and Relaxation Convergence property (Lemma 24.14) If s ~ u v is a shortest path from s to v in G, and if d[u] = (s, u) at any time prior to relaxing edge (u, v), then d[v] = (s, v) at all times afterward. Path-relaxation property (Lemma 24.15) If p = is a shortest path from s to v k, and the edges of p are relaxed in the order (s, v 1 ), (v 1, v 2 ), …, (v k-1, v k ), then after relax all the edges, d[v k ] = (s, v k ). Note that other relaxations may take place among these relaxations.

14
2004 SDU 14 Properties of Shortest Paths and Relaxation Predecessor-subgraph property (Lemma 24.17) Once d[v] = (s, v) for all v V, the predecessor sub- graph is a shortest-paths tree rooted at s. Predecessor subgraph G = (V , E ), where –V = {v V : [v] Nil} {s} –E = {( [v], v) E : v V -{s}} Note: Proofs for all these properties can be found in your textbook, Page 230-236.

15
2004 SDU 15 Shortest-Paths Tree Let G = (V, E) be a weighted, directed graph with source s and weight function w: E R, and assume that G contains no negative cycles that are reachable from s. A shortest-paths tree rooted at s is a directed sub- graph G’=(V’, E’), where V’ V and E’ E, such that V’ is the set of vertices reachable from s in G, G’ forms a rooted tree with root s, and For all v V’, the unique simple path from s to v in G’ is a shortest path from s to v in G. The shortest-path tree may not be unique.

16
2004 SDU 16 The Bellman-Ford Algorithm Solve the single-source shortest-paths problem The algorithm returns a boolean value indicating whether or not there is a negative-weight cycle that is reachable from the source. If there is a negative-weight cycle reachable from the source s, the algorithm indicates that no solution exists. If there are no such cycles, the algorithm produces the shortest paths and their weights. Exercise 24.1-4

17
2004 SDU 17 The Bellman-Ford O(VE)-time Algorithm

18
2004 SDU 18 Edges are relaxed in the order: (t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y)

19
2004 SDU 19 Correctness of The Bellman-Ford Lemma 24.2 Let G = (V, E) be a weighted, directed graph with source s and weight function w: E R, and assume that G contains no negative cycles that are reachable from s. Then, after the | V | - 1 iterations of the for loop of lines 2-4 of B ELLMAN -F ORD, we have d[v] = (s, v) for all vertices v reachable from s.

20
2004 SDU 20 Proof of Lemma 24.2 Proof: Consider any vertex v that is reachable from s, and let p =, where v 0 = s and v k = v, be any acyclic shortest path from s to v. Path p has at most | V |-1 edges, and so k | V |-1. Each of the | V |-1 iterations of the for loop of lines 2-4 relaxes all E edges. Among the edges relaxed in the ith iteration, the edge in P is (v i-1, v i ), for i = 1, 2, …, k. By the path-relaxation property, d[v] = d[v k ] = (s, v k ) = (s, v).

21
2004 SDU 21 Correctness of The Bellman-Ford Corollary 24.3 Let G = (V, E) be a weighted, directed graph with source s and weight function w: E R. Then for each vertex v V, there is a path from s to v if and only if B ELLMAN -F ORD terminates with d[v] < ∞ when it is run on G. Exercise 24.1-2.

22
2004 SDU 22 Correctness of The Bellman-Ford Theorem 24.4 Let B ELLMAN -F ORD be run on a weighted, directed graph G = (V, E) with source s and weight function w: E R. If G contains no negative cycles that are reachable from s, then the algorithm returns TRUE, we have d[v] = (s, v) for all vertices v V, and the predecessor sub-graph G is a shortest-paths tree rooted at s. If G does contain a negative weight cycle reachable from s, then the algorithm returns FALSE.

23
2004 SDU 23 Proof of Theorem 24.4 1.Suppose G contains no negative-weight cycles that are reachable from s. Prove d[v] = (s, v) for all vertices in V. Prove that the algorithm returns TRUE For each edge (u, v), d[v] = (s, v) (s, u) + w(u, v) = d[u] + w(u, v). 2.Suppose that G contains a negative-weight cycle that is reachable from s. Prove that the algorithm returns FALSE Otherwise, for each edge on a negative-weight cycle C=, d[v i ] d[v i+1 ] + w(v i,v i+1 ), 1 i k. Summing both sides of equations yields 0 w(C), contradiction.

24
2004 SDU 24 Single-Source Shortest Paths in Directed Acyclic Graphs Time Complexity: O(V + E)

25
2004 SDU 25

26
2004 SDU 26 Correctness of the Algorithm Lemma 24.5 If a weighted, directed graph G = (V, E) has source vertex s and no cycles, then at the termination of the D AG -S HORTEST -P ATHS procedure, d[v] = (s, v) for all vertices v V, and the predecessor sub-graph G is a shortest-paths tree rooted at s. Proof. According to path relaxation property.

Similar presentations

Presentation is loading. Please wait....

OK

Chapter 25: All-Pairs Shortest-Paths

Chapter 25: All-Pairs Shortest-Paths

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on 5 star chocolate desserts Ppt on aditya birla group of companies Ppt on center lathe machine Ppt on power diode rectifier Ppt on operating system linux Ppt on computer languages for gaming Good backgrounds for ppt on social media Ppt on mechanical properties of dental materials Free download ppt on revolt of 1857 Nervous system for kids ppt on batteries