5/27/03CSE 202 - Shortest Paths CSE 202 - Algorithms Shortest Paths Problems.

Slides:



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

Single Source Shortest Paths
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
November 14, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Aalborg University
Advanced Algorithm Design and Analysis (Lecture 7) SW5 fall 2004 Simonas Šaltenis E1-215b
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
CSE 101- Winter ‘15 Discussion Section January 26th 2015.
Chapter 25: All-Pairs Shortest-Paths
More Graph Algorithms Minimum Spanning Trees, Shortest Path Algorithms.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Chapter 23 Minimum Spanning Trees
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.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Shortest Path Problems
CSE 421 Algorithms Richard Anderson Dijkstra’s algorithm.
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.
CSE Shortest Paths1 Midterm page 1 The worst-case complexity of an algorithm is... a function from N (or size of instance) to N.  (n lg n) is...
12/3CSE NP-complete CSE Algorithms NP Completeness Approximations.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
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 Paths Definitions Single Source Algorithms
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
CSE Algorithms Minimum Spanning Trees Union-Find Algorithm
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.
All-Pairs Shortest Paths
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
11/26/02CSE FFT,etc CSE Algorithms Polynomial Representations, Fourier Transfer, and other goodies. (Chapters 28-30)
CS 473 All Pairs Shortest Paths1 CS473 – Algorithms I All Pairs Shortest Paths.
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.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
1 Shortest Path Algorithms Andreas Klappenecker [based on slides by Prof. Welch]
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 WEEK 9-10 Graphs II Unweighted Shortest Paths Dijkstra’s Algorithm Graphs with negative costs Acyclic Graphs Izmir University of Economics.
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.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
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).
All-Pairs Shortest Paths & Essential Subgraph 01/25/2005 Jinil Han.
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.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
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)
Shortest Path Graph Theory Basics Anil Kishore.
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.
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.
Shortest Paths CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Data Structures & Algorithms Shortest Paths Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
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.
CS 361 – Chapter 14 Weighted graph –How would you represent? Shortest path algorithms from 1 vertex to any other: –General –Handling negative weight –Acyclic.
1 Weighted Graphs. 2 Outline (single-source) shortest path –Dijkstra (Section 4.4) –Bellman-Ford (Section 4.6) (all-pairs) shortest path –Floyd-Warshall.
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
Single Source Shortest Paths Chapter 24 CSc 4520/6520 Fall 2013 Slides adapted from George Bebis, University of Reno, Nevada.
11/21/02CSE Max Flow CSE Algorithms Max Flow Problems.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington These slides are.
CSE 326: Data Structures Lecture #23 Dijkstra and Kruskal (sittin’ in a graph) Steve Wolfman Winter Quarter 2000.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Single-Source Shortest Paths
CSE Algorithms Max Flow Problems 11/21/02 CSE Max Flow.
Presentation transcript:

5/27/03CSE Shortest Paths CSE Algorithms Shortest Paths Problems

CSE Shortest Paths2 Shortest Paths Problems Given a weighted directed graph, is a path of weight 29 from u to z. is another path from u to z; it has weight 16 and is the shortest path from u to z. u z t y w v x

CSE Shortest Paths3 Variants of Shortest Paths Problems A. Single pair shortest path problem Given s and d, find shortest path from s to d. B. Single source shortest paths problem Given s, for each d find shortest path from s to d. C. All-pairs shortest paths problem For each ordered pair s,d, find shortest path. (A) and (B) seem to have same asymptotic complexity. (C) takes longer, but not as long as repeating (B) for each s.

CSE Shortest Paths4 More Shortest Paths Variants 1.All weights are non-negative. 2.Weights may be negative, but no negative cycles (A cycle is a path from a vertex to itself.) 3.Negative cycles allowed. Algorithm reports “-  ” if there is a negative cycle on path from source to destination (2) and (3) seem to be harder than (1). u w v uvw u058 v-303 w-60 u w v uvw u0-- -- v  -- -- w  -- --

CSE Shortest Paths5 Single Source Shortest Paths Non-negative weights (problem B-1): From source, construct tree of shortest paths. Why is this a tree? Is this a Minimum Spanning Tree? Basic approach: label nodes with shortest path found so far. Relaxation step: choose any edge (u,v). If it gives a shorter path to v, update v ’s label s s relaxing this edge improves this node

CSE Shortest Paths6 Single Source Shortest Paths Simplest strategy: –Keep cycling through all edges –When all edges are relaxed, you’re done. What is upper bound on work? Improvement: Mark nodes when we’re sure we have best path. Key insight: if you relax all edges out all marked nodes, the unmarked node that is closest to source can be marked. You can relax edge (u,v) only once - just after u is marked. O(V 2 ) algorithm: mark node; relax its edges; find new min to mark. Dijkstra’s algorithm: Keep nodes on min-priority queue – need E Decrease-Key’s. Gives O(E lg V) - when is this faster? (Aside: can also get O(E + V lg V) using Fibonacci heap.)

CSE Shortest Paths7 Single Source Shortest Paths Negative weights allowed (problem B-2 and B-3) Why can’t we just add a constant to each weight? Why doesn’t Dijkstra’s algorithm work for B-2 ? Bellman-Ford: Cycle through edges V-1 times. O(VE) time. PERT chart: Arbitrary weights, graph is acyclic: Is there a better algorithm than Bellman-Ford?

CSE Shortest Paths8 All-pairs Shortest Paths Naïve #1: Solve V single-source problems. –O(V 2 E) for general problem. –O(V 3 ) or O(V E lg V) for non-negative weights. Naïve #2: Let d k (i,j) = shortest path from i to j involving  k edges. d 1 (i,j) = is original weight matrix. Compute d k+1 ’s from d k ’s by seeing if adding edge helps: d k+1 (i,j) = Min { d k (i,m) + d 1 (m,j) } Hmmm...this looks a lot like matrix multiplication If there are no negative cycles, d V-1 (i,j) is solution. If there is a negative cycle, then d V-1  d V Complexity is O(V 4 )

CSE Shortest Paths9 All-pairs Shortest Paths No negative cycles – Divide and Conquer says: “Shortest path from a to b with at most 2 k+1 hops is a shortest path from a to c with at most 2 k hops followed by one from c to b with at most 2 k hops.” T(k+1) = T(k) + V 3 so T(lg V) is O(V 3 lg V). This also looks like matrix multiplication, using d 2k = d k x d k instead of d k+1 = d k x d 1

CSE Shortest Paths10 All-pairs Shortest Paths No negative cycles – Dynamic Programming approach: Number cities 1 to V. Let S(a,b,k) be length of shortest path from a to b that uses only cities {1,2,...,k} as intermediate points. Intuition: At first (k=0), there are only direct flights between cities. Then (k=1) they allow city 1 to be an intermediate connection point. Then (k=2) they add city 2 as a possible connection point. Etc. Claim: S(a,b,k) = min{ S(a,b,k-1), S(a,k,k-1) + S(k,b,k-1) }. Intuition: either adding k as a possible connection point doesn’t shorten the trip, or it does. “No negative cycles”  needn’t consider paths going through k twice. Complexity: T(k+1)= T(k) + cV 2, and T(0) is 0. Thus, T(V) is  (V 3 ). This is the Floyd-Warshall algorithm

CSE Shortest Paths11 Johnson’s All-Pairs Shortest Paths Motivation: for sparse non-negative weights, “O(V E lg V)” is better than “O(V 3 )” We’ll convert “arbitrary weights” (C3) to “non- negative” (C1) problem via reweighting. Dijkstra V times Floyd-Warshall Starting bonus or finishing penalty

CSE Shortest Paths12 Johnson’s Algorithm Reweighting can make all edges non-negative Make node-weight(x) = shortest path to x from anywhere. Sounds like all-pairs problem Slick trick use Bellman-Ford (only O(VE) time) s

CSE Shortest Paths13 Glossary (in case symbols are weird)            subset  element of  infinity  empty set  for all  there exists  intersection  union  big theta  big omega  summation  >=  <=  about equal  not equal  natural numbers(N)  reals(R)  rationals(Q)  integers(Z)