1 / 28

Shortest-path problems Single-source shortest path All-pair shortest path

Lecture 8 Shortest Path. Shortest-path problems Single-source shortest path All-pair shortest path. Overview. Shortest-path problems Single-source shortest path algorithms Bellman-Ford algorithm Dijkstra algorithm All-Pair shortest path algorithms Floyd- Warshall algorithm.

Download Presentation

Shortest-path problems Single-source shortest path All-pair shortest path

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 8 Shortest Path • Shortest-path problems • Single-source shortest path • All-pair shortest path

  2. Overview • Shortest-path problems • Single-source shortest path algorithms • Bellman-Ford algorithm • Dijkstra algorithm • All-Pair shortest path algorithms • Floyd-Warshall algorithm

  3. Weighted graph Beijing Qingdao Lhasa Shanghai • Single-source shortest path • All-pair shortest path Guangzhou

  4. Shortest Path

  5. Shortest Path Optimal substructure: Subpaths of shortest paths are shortest paths. Cycles. Can a shortest path contains cycles? Negative weights.

  6. Where are we? • Shortest-path problems • Single-source shortest path algorithms • Bellman-Ford algorithm • Dijkstra algorithm • All-Pair shortest path algorithms • Floyd-Warshall algorithm

  7. Relaxing The process of relaxingan edge (u,v)consists of testing whether we can improve the shortest path to vfound so far by going through u.

  8. Shortest-path properties Notation: We fix the source to be s. λ[v]: the length of path computed by our algorithms from s to v. δ[v]: the length of the shortest path from s to v. Triangle property δ[v] <= δ[u] + w(u,v) for any edge (u,v). Upper-bound property δ[v] <= λ[v] for any vertex v. Convergence property If s⇒u→v is a shortest path, and if λ[u] = δ[u], then after relax(u,v), we have λ[v] = δ[v].

  9. Θ(mn) Bellman-Ford algorithm E = {(t,x),(t,y),(t,z),(x,t),(y,x),(y,z),(z,x),(z,s),(s,t),(s,y)}

  10. Negative cycle

  11. Proof. No negative cycle. By the fact that the length of simple paths is bounded by |V| - 1. After i-th iteration of relax, λ[vi] = δ[vi]. s v1 Vj vi v Correctness Correctness of Bellman-Ford If G contains no negative-weight cycles reachable from s, then the algorithm returns TRUE, and for all v, λ[v] = δ[v], otherwise the algorithm returns FALSE. Negative cycle. After i-th iteration of relax, λ[vi] + w(vi,vj) < λ[vj]. The length of negative cycle is at most |V|.

  12. s v1 vj vi v • Θ(m) Observation 1 If there is no cycle (DAG), ... Relax in topological order.

  13. seam Weighted DAG application

  14. Observation 2 If there is no negative edge, ... vj vi v1 s If (s, vi) is the lightest edge sourcing from s, then λ[vi] = δ[vi]

  15. Dijkstra algorithm Edsger Wybe Dijkstra in 2002

  16. Dijkstra algorithm

  17. Correctness Assume u is chosen in Step 7, and 1. λ[u] > δ[u] 2. s ⇒ x → y ⇒ u is the shortest path δ[u] = δ[x] + w(x,y) + w(p2) = λ[x] + w(x,y) + w(p2) ≥ λ[x] + w(x,y) ≥ λ[y] ≥ λ[u]

  18. Θ(n2) Time complexity

  19. What is the time complexity? • How about use d-heap?

  20. Comparisons

  21. Dense graph • dense: m = n1+ε, ε is not too small. • d-heap, d = m/n • complexity: O(dnlogdn + mlogdn) = O(m)

  22. Where are we? • Shortest-path problems • Single-source shortest path algorithms • Bellman-Ford algorithm • Dijkstra algorithm • All-Pair shortest path algorithms • Floyd-Warshall algorithm

  23. All-pairs shortest path

  24. Floyd-Warshall algorithm

  25. Θ(n3) Floyd-Warshall algorithm

  26. Conclusion Dijkstra’s algorithm. • Nearly linear-time when weights are nonnegative. Acyclic edge-weighted digraphs. • Faster than Dijkstra’s algorithm. • Negative weights are no problem. Negative weights and negative cycles. • If no negative cycles, can find shortest paths via Bellman-Ford. • If negative cycles, can find one via Bellman-Ford. All-pair shortest path. • can be solved via Floyd-Warshall • Floyd-Warshall can also compute the transitive closure of directed graph.

  27. Which of the following statements are true for shortest path? ♠. If you run Dijkstra's algorithm on an edge-weighted DAG with positive weights, the order in which the vertices are relaxed is a topological order. ♥. Let P be a shortest path from some s to t in an edge-weighted digraph G. If the weight of each edge in G is increased by one, then P will still be a shortest path from s to t in the modified digraph G'. ♣. Let G be a digraph with positive edge weights. Suppose that you increase the length of an edge by x. Then, the length of the shortest path from s to t can increase by more than x. ♦. Bellman-Ford finds the shortest simple path from s to every other vertex, even if the edge weights are positive or negative integers, provided there are no negative cycles.

More Related