All-Pairs Shortest Paths

Slides:



Advertisements
Similar presentations
1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine.
Advertisements

Single Source Shortest Paths
Graphs: MSTs and Shortest Paths David Kauchak cs161 Summer 2009.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Advanced Algorithm Design and Analysis (Lecture 7) SW5 fall 2004 Simonas Šaltenis E1-215b
CS138A Single Source Shortest Paths Peter Schröder.
1 Theory I Algorithm Design and Analysis (10 - Shortest paths in graphs) T. Lauer.
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
CSE 101- Winter ‘15 Discussion Section January 26th 2015.
Chapter 25: All-Pairs Shortest-Paths
More Graph Algorithms Minimum Spanning Trees, Shortest Path Algorithms.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
All Pairs Shortest Paths and Floyd-Warshall Algorithm CLRS 25.2
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.
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.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Shortest Path Problems
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
1 8a-ShortestPathsMore Shortest Paths in a Graph (cont’d) Fundamental Algorithms.
25.All-Pairs Shortest Paths Hsu, Lih-Hsing. Computer Theory Lab. Chapter 25P.2.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
Graph Algorithms Shortest path problems [Adapted from K.Wayne]
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
1 Advanced Algorithms All-pairs SPs DP algorithm Floyd-Warshall alg.
Shortest Path Algorithms
Shortest Paths Definitions Single Source Algorithms
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
Algorithms and Networks
CS 253: Algorithms Chapter 24 Shortest Paths Credit: Dr. George Bebis.
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
CS 473 All Pairs Shortest Paths1 CS473 – Algorithms I All Pairs Shortest Paths.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
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.
5/27/03CSE Shortest Paths CSE Algorithms Shortest Paths Problems.
Graph Algorithms Shortest path problems. Graph Algorithms Shortest path problems.
1 Graphs Algorithms Sections 9.1, 9.2, and Graphs v1v1 v2v2 v5v5 v7v7 v8v8 v3v3 v6v6 v4v4 A graph G = (V, E) –V: set of vertices (nodes) –E: set.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).
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.
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.
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.
Lecture 7 All-Pairs Shortest Paths. All-Pairs Shortest Paths.
Minimum weight spanning trees
Parallel Programming: All-Pairs Shortest Path CS599 David Monismith Based upon notes from multiple sources.
Minimum spanning trees (MST) Def: A spanning tree of a graph G is an acyclic subset of edges of G connecting all vertices in G. A sub-forest of G is an.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Nattee Niparnan. Dijkstra’s Algorithm Graph with Length.
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.
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
All-Pairs Shortest Paths
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
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])
TIRGUL 10 Dijkstra’s algorithm Bellman-Ford Algorithm 1.
Lecture 13 Shortest Path.
All-Pairs Shortest Paths (26.0/25)
Chapter 25: All-Pairs Shortest Paths
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Shortest Path Algorithms
Advanced Algorithms Analysis and Design
All pairs shortest path problem
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Lecture 12 Shortest Path.
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Presentation transcript:

All-Pairs Shortest Paths Definition Algorithms Using Single Source Algorithms Matrix multiplication Floyd-Warshall Both of above use adjacency matrix representation and dynamic programming Johnson’s algorithm Uses adjacency list representation

Definition Input Task Still have issue with negative weight cycles Weighted, connected directed graph G=(V,E) Weight (length) function w on each edge e in E We will typically assume w is represented as a matrix Task Compute a shortest path from all nodes in V to all nodes in V Still have issue with negative weight cycles

Using single source algorithms Call a single source algorithm from each vertex s in V O(V X) where X is the running time of the given algorithm Dijkstra linear array: O(V3) Dijkstra binary heap: O(VE log V) Dijkstra Fibonacci heap: O(V2 log V + VE) Bellman-Ford: O(V2 E) (negative weight edges)

Two adjacency matrix based algorithms Matrix-multiplication based algorithm Let Lm(i,j) denote the length of the shortest path from node i to node j using at most m edges What is our desired result in terms of Lm(i,j)? What is a recurrence relation for Lm(i,j)? Floyd-Warshall algorithm Let Lk(i,j) denote the length of the shortest path from node i to node j using only nodes within {1, …, k} as internal nodes. What is our desired result in terms of Lk(i,j)? What is a recurrence relation for Lk(i,j)?

Conceptual pictures i k j i k j OR Shortest path using at most 2m edges Try all possible nodes k i k j Shortest path using at most m edges Shortest path using at most m edges Shortest path using nodes 1 through k Shortest path using nodes 1 through k-1 i k j Shortest path using nodes 1 through k-1 OR Shortest path using nodes 1 through k-1

Running Times Matrix-multiplication based algorithm O(V3 log V) log V executions of “matrix-matrix” multiplication Not quite matrix-matrix multiplication but same running time Floyd-Warshall algorithm O(V3) V iterations of an O(V2) update loop The constant is very small, so this is a “fast” O(V3)

Johnson’s Algorithm Key ideas Reweight edge weights to eliminate negative weight edges AND preserve shortest paths Use Bellman-Ford and Dijkstra’s algorithms as subroutines Running time: O(V2 log V + VE) Better than earlier algorithms for sparse graphs

Reweighting Original edge weight is w(u,v) New edge weight: w’(u,v) = w(u,v) + h(u) – h(v) h(v) is a function mapping vertices to real numbers Key observation: Let p be any path from node u to node v w’(p) = w(p) + h(u) – h(v)

Computing vertex weights h(v) Create a new graph G’ = (V’, E’) by adding a new vertex s to V adding edges (s,v) for all v in V w(s,v) = 0 for all v in V Set h(v) to be the length of the shortest path from this new node s to node v This is well-defined if G’ does not contain negative weight cycles Note that h(v) <= h(u) + w(u,v) for all (u,v) in E’ Thus, w’(u,v) = w(u,v) + h(u) – h(v) >= 0

Algorithm implementation Run Bellman-Ford on G’ from new node s If no negative weight cycle, then use h(v) values from Bellman-Ford Now compute w’(u,v) for each edge (u,v) in E Now run Dijkstra’s algorithm using w’ Use each node as source node Modify d[u,v] at end by adding h(v) and subtracting h(u) to get true path weight Running time: O(VE) [from one run of Bellman-Ford] + O(V2 log V + VE) [from V runs of Dijkstra]