COS 423 Lecture 9 Shortest Paths II ©Robert E. Tarjan 2011.

Slides:



Advertisements
Similar presentations
Graph Algorithms - 3 Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 13Feb 12, 2014Carnegie Mellon University.
Advertisements

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
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
Chapter 5 Shortest Paths: Label-Correcting Algorithms
1 Theory I Algorithm Design and Analysis (10 - Shortest paths in graphs) T. Lauer.
chapter Single-Source Shortest Paths Problem Definition Shortest paths and Relaxation Dijkstra’s algorithm (can be viewed as a greedy algorithm)
CSE 101- Winter ‘15 Discussion Section January 26th 2015.
Introduction to Algorithms 6.046J/18.401J/SMA5503
CS38 Introduction to Algorithms Lecture 5 April 15, 2014.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
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
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 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Graph Algorithms: Part 1
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Shortest Paths Definitions Single Source Algorithms
CSE 421 Algorithms Richard Anderson Lecture 10 Minimum Spanning Trees.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Greed: Shortest Path s 3 t
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Shortest Paths1 C B A E D F
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
Chapter 4 Shortest Path Label-Setting Algorithms Introduction & Assumptions Applications Dijkstra’s Algorithm.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
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.
1 WEEK 9-10 Graphs II Unweighted Shortest Paths Dijkstra’s Algorithm Graphs with negative costs Acyclic Graphs Izmir University of Economics.
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
Spring 2015 Lecture 10: Elementary Graph Algorithms
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
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.
15.082J & 6.855J & ESD.78J September 23, 2010 Dijkstra’s Algorithm for the Shortest Path Problem.
Lecture 16. Shortest Path Algorithms
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.
1 Introduction to Algorithms L ECTURE 17 (Chap. 24) Shortest paths I 24.2 Single-source shortest paths 24.3 Dijkstra’s algorithm Edsger Wybe Dijkstra
Lecture 13 Algorithm Analysis
Graphs Part II Lecture 7. Lecture Objectives  Topological Sort  Spanning Tree  Minimum Spanning Tree  Shortest Path.
Shortest Path Algorithm 2 Prof. Sin-Min Lee Department of Computer Science.
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
15.082J & 6.855J & ESD.78J September 30, 2010 The Label Correcting Algorithm.
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.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
CS38 Introduction to Algorithms Lecture 3 April 8, 2014.
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.
EMIS 8374 Dijkstra’s Algorithm Updated 18 February 2008
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Advanced Algorithms Analysis and Design
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Autumn 2015 Lecture 10 Minimum Spanning Trees
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Fundamental Data Structures and Algorithms
Autumn 2016 Lecture 10 Minimum Spanning Trees
Advanced Algorithms Analysis and Design
CSE 417: Algorithms and Computational Complexity
Winter 2019 Lecture 10 Minimum Spanning Trees
Data Structures and Algorithm Analysis Lecture 8
Presentation transcript:

COS 423 Lecture 9 Shortest Paths II ©Robert E. Tarjan 2011

Non-negative arc lengths Use greedy method: Shortest-first scanning (Dijkstra’s algorithm): Scan a labeled vertex v with d(v) minimum, breaking a tie arbitrarily.

L = s:0 scan s s a j g d h k m l i e c f t n b

S = s:0 scan a L = a:3, j:16, g:22 s a j g d h k m l i e c f t n b

S = s:0, a:3 scan d L = d:9, j:16, g:21 s a j g d h k m l i e c f t n b

S = s:0, a:3, d:9 scan h L = h:9, j:16, g:21, k:21, e:25 s a j g d h k m l i e c f t n b

S = s:0, a:3, d:9, h:9 scan j L = j:16, g:21, k:21, e:25, i:29 s a j g d h k m l i e c f t n b

S = s:0, a:3, d:9, h:9, j:16 scan g… L = g:20, k:21, e:25, i:29 s a j g d h k m l i e c f t n b

Lemma 1: If arc lengths are non-negative, shortest-first scanning maintains the invariant that d(x) ≤ d(y) if x is scanned and y is labeled. Proof: By induction on number of scans. True initially. Suppose true before scan of v. If d(v) + c(v, w) < d(w), d(v) < d(w) since c(v, w) ≥ 0. By the choice of v to scan, w must be unlabeled or labeled. After d(w) is decreased to d(v) + c(v, w), d(v) ≤ d(w). Thus the scan preserves the invariant that if x is labeled, d(v) ≤ d(x), and the lemma remains true when v is moved to S.

Theorem 1: If arc lengths are non-negative, shortest-first scanning scans each vertex at most once. Implementation: L = heap, key of v = d(v) find v to scan: delete-min(L) label(w): after decreasing d(w), if w  U then insert(w, L) else (w  L) decrease-key(w, d(w), L)

≤n inserts, ≤n delete-mins, ≤m decrease-keys L = implicit heap or pairing heap: O(mlgn) L = rank-pairing heap: O(m + nlgn)

No cycles topological order of vertices: (v, w)  A → v before w graph is acyclic ↔  topological order Can find a topological order or a cycle in O(m) time: graph search, later lecture Topological scanning: scan vertices in topological order: each vertex scanned once, O(m) time

Scan s, a, j, g, d, e, b, c, k, l, m, h, i, n, f, t s a j g d h k m l i e c f t n b 30 – – –16 – – –

Arc-length transform Let π be any real-valued function on vertices Reduced length of (v, w): c π (v, w) = c(v, w) + π(v) – π(w) If P is a path, c π (P) = sum of c π on arcs of P If P is from v to w, c π (P) = c(P) + π(v) – π(w) → replacing c by c π preserves shortest paths, although in general it changes their lengths If C is a cycle, c π (C) = c(C) → replacing c by c π preserves cycle lengths

Goal: find a π that makes all arc lengths non- negative Solution: Single-source shortest distances via breadth-first scanning Create a dummy source s with arcs of length 0 to all other vertices (to guarantee reachability) Find shortest distances from s to all vertices If no negative cycle, let π = d: c π (v, w) = c(v, w) + d(v) – d(w) ≥ 0 Special case of linear programming duality

All-pairs shortest paths Transform arc lengths so non-negative via breadth-first scanning For each source, solve a single-source problem with non-negative arc lengths via shortest-first scanning Undo arc length transform Time = O(n(nlgn + m))

Alternative all-pairs algorithm (Floyd-Williams) Dynamic programming: For each vertex pair u, w maintain d(u, w) = length of shortest path from u to w found so far Process vertices one-by-one. To process v, consider paths containing v.

for u  V do for w  V do if u = w then d(u, w)  0 else if (u, w)  A then d(u, w)  c(u, w) else d(u, w)   for v  V do for u  V do for w  V do d(u, w) = min{d(u, w), d(u, v) + d(v, w)}

When the algorithm stops, if d(v, v) < 0 for some v, there is a negative cycle containing v; otherwise, d(u, w) is the length of a shortest path from u to w. The algorithm is very simple but its running time is Θ(n 3 ): takes no advantage of sparsity (few arcs) To exploit sparsity, only iterate over finite entries. Resembles Gaussian elimination; indeed, Gaussian elimination can be used to find shortest paths.

Single-pair shortest paths Goal: find a shortest path from s to t Assume no non-negative arc lengths One-way search: Do shortest-first scanning forward from s until t is deleted from L, or do shortest-first scanning backward from t until s is deleted from L Two-way search: Do shortest-first scanning forward from s and backward from t concurrently.

Stopping condition for two-way search Let d(v) and d’(v) be computed distance of v from s and to t, respectively Stop when some v has been deleted from both heaps (both d(v) and d’(v) are exact). The length of a shortest path from s to t is min{d(x) + d’(x)| x  V} (not necessarily d(v) + d’(v)) Exercise: prove this

One-way heuristic search Goal: avoid examining vertices of the graph other than those on a shortest path from s to t Method: use an easy-to-compute estimate e(v) of the distance from v to t to help guide shortest- first scanning from s: key of v in heap is d(v) + e(v). (e(v) = 0 is Dijkstra’s algorithm) Normalization: e(t) = 0

Examples 15 puzzle: e = number of misplaced tiles more accurate: e = sum of manhattan distances of tiles to correct positions Road network, lengths are distances e = straight-line distance (“as the crow flies”)

What must hold of e so that one scan per vertex suffices? safety: e(v) ≤ c(v, w) + e(w) for (v, w)  A If e is safe and e(t) = 0, e(v) ≤ c(P) for any path P from v to t Exercise: prove this If e is safe, d(v) when v is first scanned is the length of a shortest path from s to v Exercise: prove this