Lecture 20: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance 400 2500 1000 1800 800 900.

Slides:



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

November 14, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Aalborg University
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=
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
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.
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,
Lecture 21: Matrix Operations and All-pair Shortest Paths Shang-Hua Teng.
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 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
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
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.
BellmanFord. BellmanFord(G,w,s) 1 InitializeSingleSource(G,s) 2 for i 1 to |V[G]| do for each (u,v) E[G] 4 do Relax(u,v,w) 5 for each edge (u,v)
Shortest Paths Definitions Single Source Algorithms
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.
DAST 2005 Tirgul 13 (and more) sample questions. DAST 2005 (back to previous week) We’ve seen that solving the shortest paths problem requires O(VE) time.
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
Lecture 8 Shortest Path Shortest-path problems
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
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.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Topological Sorting and Least-cost Path Algorithms.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
David Luebke 1 9/10/2015 CS 332: Algorithms Single-Source Shortest Path.
David Luebke 1 9/10/2015 ITCS 6114 Single-Source Shortest Path.
CISC 235: Topic 11 Shortest Paths Algorithms. CISC 235 Topic 112 Outline Single-Source Shortest Paths Algorithm for Unweighted Graphs Algorithm for Weighted,
David Luebke 1 9/13/2015 CS 332: Algorithms S-S Shortest Path: Dijkstra’s Algorithm Disjoint-Set Union Amortized Analysis.
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.
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.
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
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 13 Algorithm Analysis
Graphs Part II Lecture 7. Lecture Objectives  Topological Sort  Spanning Tree  Minimum Spanning Tree  Shortest Path.
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
David Luebke 1 3/1/2016 CS 332: Algorithms Dijkstra’s Algorithm Disjoint-Set Union.
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])
David Luebke 1 11/21/2016 CS 332: Algorithms Minimum Spanning Tree Shortest Paths.
Minimum Spanning Tree Shortest Paths
Minimum Spanning Trees
Lecture 7 Shortest Path Shortest-path problems
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
CSC 413/513: Intro to Algorithms
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Shortest Path Problems
Advanced Algorithms Analysis and Design
Lecture 21: Matrix Operations and All-pair Shortest Paths
CS 3013: DS & Algorithms Shortest Paths.
Presentation transcript:

Lecture 20: Shortest Paths Shang-Hua Teng

Weighted Directed Graphs Weight on edges for distance

Shortest Paths Given a weighted, directed graph G=(V, E) with weight function w: E  R. The weight of path p= is the sum of the weights of its edges: We define the shortest-path weight from u to v by A shortest path from vertex u to vertex v is any path with w(p)=  (u, v) If there is a path from u to v, Otherwise.

Variants of Shortest Path Problem Single-source shortest paths problem –Finds all the shortest path of vertices reachable from a single source vertex s Single-destination shortest-path problem –By reversing the direction of each edge in the graph, we can reduce this problem to a single-source problem Single-pair shortest-path problem –No algorithm for this problem are known that run asymptotically faster than the best single-source algorithm in the worst case All-pairs shortest-path problem

Relaxation For each vertex v  V, we maintain an attribute d[v], which is an upper bound on the weight of a shortest path from source s to v. We call d[v] a shortest-path estimate. Possible Predecessor of v in the shortest path

Relaxation Relaxing an edge (u, v) consists of testing whether we can improve the shortest path found so far by going through u and, if so, update d[v] and  [v] By Triangle Inequality

Dijkstra’s Algorithm

Coping with Negative Weights Deciding whether there is a negative circle If the graph does not have a negative circle reachable from the source s, for the shortest path tree.

Bellman-Ford Algorithm BellmanFord() for each v  V d[v] =  ; d[s] = 0; for i=1 to |V|-1 for each edge (u,v)  E Relax(u,v, w(u,v)); for each edge (u,v)  E if (d[v] > d[u] + w(u,v)) return “no solution”; Relax(u,v,w): if (d[v] > d[u]+w) then d[v]=d[u]+w Initialize d[], which will converge to shortest-path value  Relaxation: Make |V|-1 passes, relaxing each edge Test for solution Under what condition do we get a solution?

Bellman-Ford Algorithm BellmanFord() for each v  V d[v] =  ; d[s] = 0; for i=1 to |V|-1 for each edge (u,v)  E Relax(u,v, w(u,v)); for each edge (u,v)  E if (d[v] > d[u] + w(u,v)) return “no solution”; Relax(u,v,w): if (d[v] > d[u]+w) then d[v]=d[u]+w What will be the running time?

Bellman-Ford Algorithm BellmanFord() for each v  V d[v] =  ; d[s] = 0; for i=1 to |V|-1 for each edge (u,v)  E Relax(u,v, w(u,v)); for each edge (u,v)  E if (d[v] > d[u] + w(u,v)) return “no solution”; Relax(u,v,w): if (d[v] > d[u]+w) then d[v]=d[u]+w What will be the running time? A: O(VE)

Bellman-Ford Algorithm BellmanFord() for each v  V d[v] =  ; d[s] = 0; for i=1 to |V|-1 for each edge (u,v)  E Relax(u,v, w(u,v)); for each edge (u,v)  E if (d[v] > d[u] + w(u,v)) return “no solution”; Relax(u,v,w): if (d[v] > d[u]+w) then d[v]=d[u]+w B E DC A Ex: work on board s

Bellman-Ford Note that order in which edges are processed affects how quickly it converges Correctness: show d[v] =  (s,v) after |V|-1 passes –Lemma: d[v]   (s,v) always Initially true Let v be first vertex for which d[v] <  (s,v) Let u be the vertex that caused d[v] to change: d[v] = d[u] + w(u,v) Then d[v]<  (s,v)  (s,v)   (s,u) + w(u,v)(Why?)  (s,u) + w(u,v)  d[u] + w(u,v)(Why?) So d[v] < d[u] + w(u,v). Contradiction.

Bellman-Ford Prove: after |V|-1 passes, all d values correct –Consider shortest path from s to v: s  v 1  v 2  v 3  v 4  v Initially, d[s] = 0 is correct, and doesn’t change (Why?) After 1 pass through edges, d[v 1 ] is correct (Why?) and doesn’t change After 2 passes, d[v 2 ] is correct and doesn’t change … Terminates in |V| - 1 passes: (Why?) What if it doesn’t?

Properties of Shortest Paths Triangle inequality –For any edge (u,v) in E,  (s,v) <=  (s,u) + w(u,v) Upper bound property –d[v] >=  (s,v) Monotonic property –d[v] never increase No-path property –If v is not reachable then d[v] =  (s,v) = infty

Properties of Shortest Paths Convergence property –If (u,v) is on the shortest path from s to v and if d[u] =  (s,u) at any time prior to relaxing (u,v), then d[v] =  (s,v) at all time afterward Path-relaxation property –If p= is the shortest path from s to v k and edges of p are relaxed in order in the index, then d[v k ] =  (s, v k ). This property holds regardless of any other relaxation steps that occur, even if they are intermixed with relaxations of the edges of p

Properties of Shortest Paths Predecessor-subgraph property –Once d[v] =  (s,v), the predecessor subgraph is a shortest-paths tree rooted at s

Matrix Basic Vector: array of numbers; unit vector Inner product, outer product, norm Matrix: rectangular table of numbers, square matrix; Matrix transpose All zero matrix and all one matrix Identity matrix 0-1 matrix, Boolean matrix, matrix of graphs

Matrix Operations Matrix-vector operation –System of linear equations –Eigenvalues and Eigenvectors Matrix matrix operations

1. Matrix Addition:

2. Scalar Multiplication:

3. Matrix Multiplication