Single Source Shortest Paths

Similar documents
Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Single Source Shortest Path

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

Shortest Path Problem

Single Source Shortest Path (SSSP) Problem

Minimum Spanning Trees

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 20. Example. Shortest Paths Definitions

from notes written mostly by Dr. Carla Savage: All Rights Reserved

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24

Lecture 11: Analysis of Algorithms (CS ) 1

Shortest Paths. Shortest Path. Applications. CSE 680 Prof. Roger Crawfis. Given a weighted directed graph, one common problem is finding the shortest

Unit 5F: Layout Compaction

Unit 3: Layout Compaction

Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4.

Algorithms on Graphs: Part III. Shortest Path Problems. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

Week 12: Minimum Spanning trees and Shortest Paths

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

COMP251: Single source shortest paths

COL 702 : Assignment 1 solutions

COT 6405 Introduction to Theory of Algorithms

Sample Solutions to Homework #4

Outlines: Graphs Part-2

5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456

Introduction to Algorithms. Lecture 11

Shortest Paths. Nishant Mehta Lectures 10 and 11

Lecture 18 Graph-Based Algorithms. CSE373: Design and Analysis of Algorithms

ECE250: Algorithms and Data Structures Single Source Shortest Paths Bellman-Ford Algorithm

Shortest Paths. Nishant Mehta Lectures 10 and 11

Unit 2: Algorithmic Graph Theory

22 Elementary Graph Algorithms. There are two standard ways to represent a

Dijkstra s Algorithm

TIE Graph algorithms

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Design and Analysis of Algorithms 演算法設計與分析. Lecture 13 December 18, 2013 洪國寶

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

Introduction Single-source shortest paths All-pairs shortest paths. Shortest paths in graphs

Algorithm Design and Analysis

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck

6.006 Introduction to Algorithms Spring 2008

Introductory Computer Programming: Shortest Path Algorithms

Dijkstra s Shortest Path Algorithm

Algorithms for Data Science

Algorithm Design and Analysis

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.

Shortest path problems

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution

Lecture I: Shortest Path Algorithms

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Shortest Path Algorithms

1 Dijkstra s Algorithm

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

Basic Graph Algorithms

Outline. Computer Science 331. Definitions: Paths and Their Costs. Computation of Minimum Cost Paths

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

CS 270 Algorithms. Oliver Kullmann. Breadth-first search. Analysing BFS. Depth-first. search. Analysing DFS. Dags and topological sorting.

Quiz 2 Practice Problems

CS 561, Lecture 10. Jared Saia University of New Mexico

24 Single-Source Shortest Paths

Section authors: Hamilton Clower, David Scott, Ian Dundore.

Single-Source Shortest Paths. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Graph Representation

Chapter 22. Elementary Graph Algorithms

Classical Shortest-Path Algorithms

CS350: Data Structures Dijkstra s Shortest Path Alg.

CS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.

Solving Difference Constraints Incrementally

Algorithms and Data Structures 2014 Exercises and Solutions Week 9

22 Elementary Graph Algorithms. There are two standard ways to represent a

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

CS 561, Lecture 10. Jared Saia University of New Mexico

Representations of Graphs

Dijkstra s Algorithm. Dijkstra s algorithm is a natural, greedy approach towards

Graph: representation and traversal

Two-Levels-Greedy: a generalization of Dijkstra s shortest path algorithm

Artificial Intelligence

Shortest Path Problems

Minimum Spanning Trees

Exam 3 Practice Problems

Week 5. 1 Analysing BFS. 2 Depth-first search. 3 Analysing DFS. 4 Dags and topological sorting. 5 Detecting cycles. CS 270 Algorithms.

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

Introduction to Algorithms April 16, 2008 Massachusetts Institute of Technology Spring 2008 Professors Srini Devadas and Erik Demaine Quiz 2

Fundamental Algorithms CSCI-GA /Summer Solution to Homework 8

CS473-Algorithms I. Lecture 14-A. Graph Searching: Breadth-First Search. Cevdet Aykanat - Bilkent University Computer Engineering Department

Parallel Graph Algorithms

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1

Graph Algorithms. Definition

Graph representation

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Nikos Anastopoulos, Konstantinos Nikas, Georgios Goumas and Nectarios Koziris

Algorithm Design, Anal. & Imp., Homework 4 Solution

EE/CSCI 451 Spring 2018 Homework 8 Total Points: [10 points] Explain the following terms: EREW PRAM CRCW PRAM. Brent s Theorem.

Graphs & Digraphs Tuesday, November 06, 2007

Sources for this lecture 2. Shortest paths and minimum spanning trees

Transcription:

Single Source Shortest Paths Given a connected weighted directed graph G(V, E), associated with each edge u, v E, there is a weight w(u, v). The single source shortest paths (SSSP) problem is to find a shortest path from a given source r to every other vertex v V {r}. The weight (length) of a path p = v 0, v 1,..., v k is the sum of the weights of its constituent edges: w(p) = k w(v i 1, v i ). i=1 The weight of a shortest path from u to v is defined by δ(u, v) = min{w(p) : p is a path from u to v}. 1 Negative Cycles In some applications, graphs may contain edges with negative weights. Such edges may result in negative cycles (e.g. Figure 1). If there is a negative weight cycle which is reachable from the source s, the weight δ(s, v) is undefined, where v is a vertex in the cycle. 2 Representation of a shortest path tree The shortest path tree rooted at s is a directed subgraph G = (V, E ) where V V and E E such that every v V is reachable from s; and for all v V, the unique simple path in G from s to v is a shortest path from s to v in G. In other words, for each vertex v V, we maintain a predecessor p(v) that is either a vertex or NIL. Thus, the output for a single shortest paths problem is a tree rooted at the source. 3 Initialization The algorithms introduced here make use of a common initialization that is as follows: 1

Figure 1: Shortest paths from root vertex s. Negative cycles are formed by g and h, as well as b, c, and f. δ(a, g), δ(a, h), and δ(a, i) are because of the negative cycle formed by g and h. The weights for b, c and f are, despite of the negative cycle, because they are unreachable from root vertex s. Figure 2: Shortest Path Tree. The shortest path tree rooted at s has its edges in bold. Two variants (a) and (b) are shown for the same graph. In (a) vertex t is reached through the edge (q, t), whereas in (b), edge (p, t) is used instead. 2

Initialize(G, s) 1 d[s] 0 2 p[s] NIL 3 for all v V {s} 4 do d[v] 5 p[v] NIL 4 Shortest Paths and Relaxation The main technique used by the shortest path algorithms introduced here is relaxation, a method that repeatedly decreases an upper bound on the length of an actual shortest path for each vertex until the upper bound equals the length of the shortest path. For each vertex v, we maintain an attribute d[v] which is an upper bound on the length of a shortest path from source s to v. d[v] is also called the shortest path estimate. Relax(u, v, w) 1 if d[v] > d[u] + w(u, v) 2 then d[v] d[u] + w(u, v) 3 p[v] u 5 Dijkstra s Algorithm Dijkstra s algorithm assumes that all the edges in G are non-negative. The algorithm maintains a set S of vertices whose final shortest path weights from the source s have already been determined. That is, for all the vertices v S, we have d[v] = δ(s, v). The algorithm repeatedly selects a vertex u V S with the minimum shortest-path estimate, inserts u to S, and relaxes all the edges leaving u. Also, a priority queue Q that contains all the vertices in V S is maintained, keyed by their d values. Figure 3 shows the execution of the Dijkstra-Short algorithm listed below. 3

Dijkstra-Short(G, w, s) 1 Initialize(G, s) 2 S 3 Q V 4 while Q 5 do u Extract-Min(Q) 6 S S {u} 7 for each vertex v Adj[u] 8 do Relax(u, v, w) 6 The Bellman-Ford Algorithm Like Dijkstra s algorithm, the Bellman-Ford algorithm uses the technique of relaxation, progressively decreasing an estimate d[v] on the weight of a shortest path from a source s to each other vertex v V until it reaches the actual shortest path weight δ(s, v). The algorithm is capable of detecting negative cycles and returns true if and only if the graph contains no negative cycles that are reachable from the source. If Bellman-Ford returns true, then we have d[u] = δ(s, v) for all vertices v. Also, for all v V not reachable from s, δ(s, v) =. Figure 4 shows the execution of the Bellman-Ford algorithm listed below on an example graph. Bellman-Ford(G, w, s) 1 Initialize(G, s) 2 for i 1 to V 1 3 do for each edge (u, v) E 4 do Relax(u, v, w) 5 for each edge (u, v) E 6 do if d[v] > d[u] + w(u, v) 7 then return FALSE 8 return TRUE 7 Single-Source Shortest Paths in DAGs By relaxing the edges in a DAG according to their topological sort of its vertices. We can achieve Θ(n + m) time complexity. 4

Figure 3: Execution of Dijkstra-Short. Step (a) shows the state of the graph after initialisation. In step (b), vertex s (the source) is extracted (shaded gray) from Q and the adjacent vertices a and e relaxed. Since d[a] > d[s]+w(s, a), d[a] is updated and p[a] set to s (arrow from s to a is made bold). Ditto for vertex e. In step (c), vertex e is extracted (and shaded) as it is Q s minimum. As before, its adjacent vertices are relaxed. Step (d) illustrates the Relax mechanism. Here a is extracted and b and f relaxed. 5 In doing so, f s parent is updated to a (formerly e). This execution carries on until Q is empty.

Figure 4: Executing Bellman-Ford. Step (a) shows the state of the graph after initialisation. In each of the V 1 iterations, we assume that the edges are visited in a left to right order (s, a), (s, b), (s, e), (a, f),... (q, r). Due to this visiting order, within iteration 1, vertex q is first relaxed through edge (f, q), setting d[q] to 8. Soon after, edge (p, q) is considered and d[q] set to 7. Accordingly, p[q] is also updated. 6

Figure 5: Excution of DAG-Shortest. Step (a) shows the state of the graph after initialisation. Following this, the vertices are considered in topological order: c, s, i, and then t. As each vertex u is considered, vertices in Adj[u] are relaxed. DAG-Shortest(G, w, s) 1 Topologically sort the vertices of G 2 Initialize(G, s) 3 for each vertex u taken in topologically sorted (increasing) order 4 do for v Adj[u] 5 do Relax(u, v, w) Figure 5 shows an example execution of DAG-Shortest on a DAG. 8 Difference constraints and shortest paths Linear Programming: Given an m n matrix A, an m-vector b, and an n-vector c, we wish to find a vector x of n elements that maximise the objective function n i=1 c ix i subject to the m constraints given by Ax b. Approaches to solving linear programming. 7

Simplex algorithm Ellipsoid algorithm Karmarkkar s algorithm 9 Systems of difference constraints Special linear programming: each row of the linear programming matrix A contains 1 or -1, and all other entries of A are 0s. Thus, the constraints can be expressed as x j x i b k where 1 i, j n and 1 k m. For example, a set of four unknowns {x 1, x 2, x 3, x 4 }, and 6 difference constraints: x 1 x 2 6 x 1 x 3 4 x 2 x 3 10 x 3 x 4 14 x 4 x 2 4 x 4 x 1 10... can be represented as... 1 1 0 0 1 0 1 0 0 1 1 0 0 0 1 1 0 1 0 1 1 0 0 1 x 1 x 2 x 3 x 4 6 4 10 14 4 10 Given a system Ax b of difference constraints, the corresponding constraint graph is a weighted directed graph G = (V, E) where V = {v 0, v 1, v 2,..., v n }... where n is the number of unknowns, v 0 is a special source vertex created, and v i corresponds to x i for 1 i n. Also, the set of edges... E = { v i, v j : x j x i b k is a constraint} { v 0, v i : i = 1,..., n} 8

Figure 6: A constraint graph constructed from our on going example using simple rules: (1) Each unknown x i maps onto a vertex v i. (2) For each constraint x j x i b k, there is an edge (v i, v j ) with weight b k. (3) Add a vertex v 0 and have edges from it to all other vertices with weight 0. Next, use one of the SSSP algorithms to solve d[v i ] for 0 i n; using v 0 as the source. Theorem: Given a system Ax b of difference constraints, let G be the corresponding constraint graph. If G contains no negative weight cycles, then x = {δ(v 0, v 1 ), δ(v 0, v 1 ),..., δ(v 0, v n )} is a feasible solution for the system. Figure 6 shows how this is done for the example with four unknowns above. 9