CS138A 1999 1 Single Source Shortest Paths Peter Schröder.

Slides:



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

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=
1 Chapter 26 All-Pairs Shortest Paths Problem definition Shortest paths and matrix multiplication The Floyd-Warshall algorithm.
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,
Chapter 25: All-Pairs Shortest-Paths
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
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
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
1.1 Data Structure and Algorithm Lecture 11 Application of BFS  Shortest Path Topics Reference: Introduction to Algorithm by Cormen Chapter 25: Single-Source.
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.
Graph Algorithms Shortest path problems [Adapted from K.Wayne]
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)
Graph Algorithms: Shortest Path We are given a weighted, directed graph G = (V, E), with weight function w: E R mapping.
Shortest Paths Definitions Single Source Algorithms
DAST 2005 Tirgul 12 (and more) sample questions. DAST 2005 Q.We’ve seen that solving the shortest paths problem requires O(VE) time using the Belman-Ford.
Analysis of Algorithms CS 477/677 Shortest Paths Instructor: George Bebis Chapter 24.
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
All-Pairs Shortest Paths
CS 473 All Pairs Shortest Paths1 CS473 – Algorithms I All Pairs Shortest Paths.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
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.
CS223 Advanced Data Structures and Algorithms 1 The Bellman-Ford Shortest Path Algorithm Neil Tang 03/11/2010.
Graph Algorithms Shortest path problems. Graph Algorithms Shortest path problems.
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.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
All-pairs Shortest Paths. p2. The structure of a shortest path: All subpaths of a shortest path are shortest paths. p : a shortest path from vertex i.
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.
The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every.
Introduction to Graphs And Breadth First Search. Graphs: what are they? Representations of pairwise relationships Collections of objects under some specified.
Lecture 13 Algorithm Analysis
All-Pairs Shortest Paths
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
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.
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])
CS138A Elementary Graph Algorithms Peter Schröder.
Algorithms and Data Structures Lecture XIII
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Page 620 Single-Source Shortest Paths
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Basic Graph Algorithms
CS 583 Analysis of Algorithms
2018/12/27 chapter25.
Advanced Algorithms Analysis and Design
Lecture 11 Topics Application of BFS Shortest Path
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Advanced Algorithms Analysis and Design
Negative-Weight edges:
CS 3013: DS & Algorithms Shortest Paths.
Presentation transcript:

CS138A Single Source Shortest Paths Peter Schröder

CS138A Definitions Shortest path problems weighted directed graph G=(V,E) with real valued weight function w weight of a path v 0,v 1,…,v k is sum of edge costs shortest path negative weight edges negative weight cycles representation of shortest path

CS138A Shortest Paths Predecessor subgraph G p =(V p,E p ) contains all vertices reachable from source and edges induced by predecessor relationship eventually G p will be shortest paths tree shortest paths are not necessarily unique nor are the shortest path trees

CS138A Relaxation Finding shortest paths by relaxation Lemma 1: optimal substructure property; any subpath of a shortest path is itself a shortest path Corollary 2: suppose a shortest path from s to v can decomposed into a path from s to u and the edge (u,v) then the cost of the shortest path from s to v is the sum of the cost of the shortest path from s to u plus w(u,v)

CS138A Relaxation Shortest path properties Lemma 3: Let G=(V,E) be a weighted directed graph with weight function w and source s. Then for all edges (u,v) in E we have all algorithms will use relaxation; each vertex contains a field d[] containing an upper bound for the shortest path length; this will repeatedly be reduced

CS138A Shortest Paths Algorithm 1. Initialize-Single-Source(G,s) 2. for( v in V[G] ) 3. d[v] = infinity; p[v] = nil; 4. d[s] = 0 1. Relax(u,v,w) 2. if( d[v] > d[u] + w(u,v) ) 3. d[v] = d[u] + w(u,v) 4. p[v] = u;

CS138A Algorithms Main differences order in which edges are relaxed number of times each edge is relaxed Properties Lemma 4: Let G=(V,E) be weighted, directed graph with weight function w; then immediately after relaxing (u,v) in E we have

CS138A Relaxation Properties Lemma 5: Let G=(V,E) be a weighted, directed graph with weight function w and source s; after intialization for all v in V and this invariant is maintained during relaxation. Moreover, once d[v] achieves its lower bound it never changes again Corollary 6: suppose a vertex is not reachable; then the above still holds

CS138A Relaxation Properties Lemma 7: Let G=(V,E) bawdgwwfw and source s; let s to u to v be a shortest path in G for some vertices u,v; after initialization suppose a sequence of relaxation steps including Relax(u,v,w) is run; if any time prior to the call then anytime thereafter

CS138A Dijkstra’s Algorithm Single source shortest paths algorithm for a directed, weighted graph G=(V,E) with all edge weights non-negative 1. Dijkstra(G,w,s) 2. Initialize-Single-Source(G,s) 3. S = {}; Q = V[G]; 4. while( !Q.empty() ) 5. u = Q.extractMin(); S = S + {u} 6. for( v in Adj[u] ) 7. Relax(u,v,w)

CS138A Analysis Complexity Correctness greedy strategy… optimal substructure property already established Theorem 10: when running Dijkstra on a weighted directed graph with non-negative weight function w from s then at termination for all u in V

CS138A Bellman-Ford Single source shortest paths algorithm allows for negative weight edges but of course no negative weight cycles 1. Bellmann-Ford(G,s) 2. Initialize-Single-Source(G,s) 3. for( i = 1 to |V[G]|-1 ) 4. for( (u,v) in E[G] ) 5. Relax(u,v,w) 6. for( (u,v) in E[G] ) 7. if( d[v] > d[u] + w(u,v) ) 8. return false 9. return true

CS138A Analysis Complexity Correctness Lemma 12: Let G=(V,E) be a weighted directed graph with source s and weight function w and assume it contains no negative weight cycles reachable from s. Then upon termination of Bellman-Ford we have for all vertices u reachable from s

CS138A Analysis Correctness Theorem 14: Let Bellman-Ford be run on a wdgwssawfw and no negative weight cycles reachable from s then the algorithm returns true and for all u in V and the predecessor subgraph G p is a shortest paths tree rooted at s. If G contains a negative weight cycles reachable from s it will return false.

CS138A Predecessor Graphs Still have to prove things about predecessor trees… Lemma 8: Let G=(V,E) be awdgwssawfw with no negative weight cycles reachable from s. Then after the graph is initialized the predecessor subgraph G p forms a rooted (at s) tree and any sequence of relaxation steps maintains this invariant.

CS138A Predecessor Subgraphs Correctness Lemma 9: Let G=(V,E) be awdgwssawfw with no negative weight cycles reachable from s. After initialization and any relaxation sequence which produces for all u in V, then the predecessor subgraph G p is a shortest paths tree rooted at s.

CS138A All Pairs Shortest paths between all pairs of vertices could run single source algorithms |V| times O(VE ln V) for Dijkstra O(V 2 E) for Bellman-Ford which can be very high… mostly use adjacency matrix representation yield predecessor matrices Example: dynamic programming solution

CS138A Approach Recall dynamic programming characterize the structure of an optimal solution recursively define the value of an optimal solution compute the solution bottom up Structure optimal substructure property (Lemma 1)

CS138A All Pairs 1. Extend-Shortest-Paths(D,W) 2. n = rows[D] 3. for( i = 1 to n ) 4. for( j = 1 to n ) 5. d’ ij = infinity 6. for( k = 1 to n ) 7. d’ = min( d’ ij, d ik + w kj ) 8. return D’