 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.

Slides:



Advertisements
Similar presentations
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Advertisements

CS138A Single Source Shortest Paths Peter Schröder.
Shortest-paths. p2. Shortest-paths problems : G=(V,E) : weighted, directed graph w : E  R : weight function P=
Single-Source Shortest- paths. p2. Shortest-paths problems : G=(V,E) : weighted, directed graph w : E  R : weight function P=
Data Structures and Algorithms Graphs Single-Source Shortest Paths (Dijkstra’s Algorithm) PLSD210(ii)
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro.
Shortest Paths Algorithm Design and Analysis Week 7 Bibliography: [CLRS] – chap 24 [CLRS] – chap 25.
chapter Single-Source Shortest Paths Problem Definition Shortest paths and Relaxation Dijkstra’s algorithm (can be viewed as a greedy algorithm)
Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,
Introduction to Algorithms 6.046J/18.401J/SMA5503
Chapter 25: All-Pairs Shortest-Paths
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
Chapter 23 Minimum Spanning Trees
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints.
CS420 lecture twelve Shortest Paths wim bohm cs csu.
CSE 780 Algorithms Advanced Algorithms Shortest path Shortest path tree Relaxation Bellman-Ford Alg.
Lecture 20: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
Lecture 19: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Shortest Path Problems
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
Analysis of Algorithms CS 477/677 Shortest Paths Instructor: George Bebis Chapter 24.
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
Lecture 8 Shortest Path Shortest-path problems
Shortest Paths1 C B A E D F
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
SINGLE-SOURCE SHORTEST PATHS. Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
CISC 235: Topic 11 Shortest Paths Algorithms. CISC 235 Topic 112 Outline Single-Source Shortest Paths Algorithm for Unweighted Graphs Algorithm for Weighted,
COSC 3101NJ. Elder Assignment 2 Remarking Assignment 2 Marks y = 0.995x R 2 = Old Mark New Mark.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
CS223 Advanced Data Structures and Algorithms 1 The Bellman-Ford Shortest Path Algorithm Neil Tang 03/11/2010.
1 Shortest Path Problems How can we find the shortest route between two points on a road map? Model the problem as a graph problem: –Road map is a weighted.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
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.
Master Method (4. 3) Recurrent formula T(n) = a  T(n/b) + f(n) 1) if for some  > 0 then 2) if then 3) if for some  > 0 and a  f(n/b)  c  f(n) for.
Introduction to Algorithms Jiafen Liu Sept
The single-source shortest path problem (SSSP) input: a graph G = (V, E) with edge weights, and a specific source node s. goal: find a minimum weight (shortest)
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
 2004 SDU Lectrue4-Properties of DFS Properties of DFS Classification of edges Topological sort.
Lecture 13 Algorithm Analysis
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
Single Source Shortest Paths Chapter 24 CSc 4520/6520 Fall 2013 Slides adapted from George Bebis, University of Reno, Nevada.
Shortest paths Given: A single source vertex (given s) in a weighted, directed graph. Want to compute a shortest path for each possible destination. (Single.
Single-Source Shortest Paths (25/24) HW: 25-2 and 25-3 p. 546/24-2 and 24-3 p.615 Given a graph G=(V,E) and w: E   weight of is w(p) =  w(v[i],v[i+1])
Minimum Spanning Trees
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
CS 583 Analysis of Algorithms
Advanced Algorithms Analysis and Design
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Shortest Path Problems
Chapter 24: Single-Source Shortest Paths
Advanced Algorithms Analysis and Design
Chapter 24: Single-Source Shortest Paths
Negative-Weight edges:
Advanced Algorithms Analysis and Design
Presentation transcript:

 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

 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).

 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.

 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?

 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.

 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?

 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).

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

 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.

 2004 SDU 10 A Relaxation Step

 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.

 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) = .

 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.

 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

 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.

 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

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

 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)

 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.

 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).

 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

 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.

 2004 SDU 23 Proof of Theorem 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.

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

 2004 SDU 25

 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.