470 likes | 752 Views
Comp 122, Fall 2003. Single-source SPs - 2. Outline. General Lemmas and Theorems.CLRS now does this last. We'll still do it first.Bellman-Ford algorithm.DAG algorithm.Dijkstra's algorithm.We will skip Section 24.4.. Comp 122, Fall 2003. Single-source SPs - 3. Corollary: Let p = SP from s t
E N D
1. Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Want to compute a shortest path for each possible destination.
Similar to BFS.
We will assume either
no negative-weight edges, or
no reachable negative-weight cycles.
Algorithm will compute a shortest-path tree.
Similar to BFS tree.
2. Comp 122, Fall 2003 Single-source SPs - 2 Outline General Lemmas and Theorems.
CLRS now does this last. Well still do it first.
Bellman-Ford algorithm.
DAG algorithm.
Dijkstras algorithm.
We will skip Section 24.4.
3. Comp 122, Fall 2003 Single-source SPs - 3 General Results (Relaxation)
4. Lemma 24.1 holds because one edge gives the shortest path, so the other edges must give sums that are at least as large. Comp 122, Fall 2003 Single-source SPs - 4
5. Comp 122, Fall 2003 Single-source SPs - 5 Relaxation
6. Comp 122, Fall 2003 Single-source SPs - 6 Properties of Relaxation d[v], if not ?, is the length of some path from s to v.
d[v] either stays the same or decreases with time
Therefore, if d[v] = ?(s, v) at any time, this holds thereafter
Note that d[v] ? ?(s, v) always
After i iterations of relaxing on all (u,v), if the shortest path to v has i edges, then d[v] = ?(s, v).
7. Comp 122, Fall 2003 Single-source SPs - 7 Properties of Relaxation
8. For lemma 24.11, note that initialization makes the invariant true at the beginning. Comp 122, Fall 2003 Single-source SPs - 8
9. Comp 122, Fall 2003 Single-source SPs - 9 More Properties
10. Lemma 24.13 follows simply from the structure of Relax.
Lemma 24.14 shows that the shortest path will be found one vertex at a time, if not faster. Thus after a number of iterations of Relax equal to V(G) - 1, all shortest paths will be found. Comp 122, Fall 2003 Single-source SPs - 10
11. Comp 122, Fall 2003 Single-source SPs - 11 Predecessor Subgraph
12. Comp 122, Fall 2003 Single-source SPs - 12 Proof of (1) (Continued)
13. Comment on Proof d[vi] ? d[vi-1] + w(vi-1, vi) for i = 1, , k1 because when Relax(vi-1 , vi , w) was called, there was an equality, and d[vi-1] may have gotten smaller by further calls to Relax.
d[vk] > d[vk-1] + w(vk-1, vk) before the last call to Relax because that last call changed d[vk]. Comp 122, Fall 2003 Single-source SPs - 13
14. Comp 122, Fall 2003 Single-source SPs - 14 Proof of (2)
15. Comp 122, Fall 2003 Single-source SPs - 15 Lemma 24.17
16. Comp 122, Fall 2003 Single-source SPs - 16 Proof (Continued)
17. And note that this shortest path tree will be found after V(G) - 1 iterations of Relax. Comp 122, Fall 2003 Single-source SPs - 17
18. Comp 122, Fall 2003 Single-source SPs - 18 Bellman-Ford Algorithm
19. So if Bellman-Ford has not converged after V(G) - 1 iterations, then there cannot be a shortest path tree, so there must be a negative weight cycle. Comp 122, Fall 2003 Single-source SPs - 19
20. Comp 122, Fall 2003 Single-source SPs - 20 Example
21. Comp 122, Fall 2003 Single-source SPs - 21 Example
22. Comp 122, Fall 2003 Single-source SPs - 22 Example
23. Comp 122, Fall 2003 Single-source SPs - 23 Example
24. Comp 122, Fall 2003 Single-source SPs - 24 Example
25. Comp 122, Fall 2003 Single-source SPs - 25 Another Look
26. Comp 122, Fall 2003 Single-source SPs - 26 Lemma 24.2
27. Comp 122, Fall 2003 Single-source SPs - 27 Correctness
28. Comp 122, Fall 2003 Single-source SPs - 28 Case 2
29. Comp 122, Fall 2003 Single-source SPs - 29 Shortest Paths in DAGs
30. Comp 122, Fall 2003 Single-source SPs - 30 Example
31. Comp 122, Fall 2003 Single-source SPs - 31 Example
32. Comp 122, Fall 2003 Single-source SPs - 32 Example
33. Comp 122, Fall 2003 Single-source SPs - 33 Example
34. Comp 122, Fall 2003 Single-source SPs - 34 Example
35. Comp 122, Fall 2003 Single-source SPs - 35 Example
36. Comp 122, Fall 2003 Single-source SPs - 36 Example
37. Comp 122, Fall 2003 Single-source SPs - 37 Dijkstras Algorithm
38. Comp 122, Fall 2003 Single-source SPs - 38 Example
39. Comp 122, Fall 2003 Single-source SPs - 39 Example
40. Comp 122, Fall 2003 Single-source SPs - 40 Example
41. Comp 122, Fall 2003 Single-source SPs - 41 Example
42. Comp 122, Fall 2003 Single-source SPs - 42 Example
43. Comp 122, Fall 2003 Single-source SPs - 43 Example
44. Comp 122, Fall 2003 Single-source SPs - 44 Correctness
45. Comp 122, Fall 2003 Single-source SPs - 45 Proof (Continued)
46. Comp 122, Fall 2003 Single-source SPs - 46 Proof (Continued)
47. Comp 122, Fall 2003 Single-source SPs - 47 Complexity