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])

Slides:



Advertisements
Similar presentations
Single Source Shortest Paths
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
CS138A Single Source Shortest Paths Peter Schröder.
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=
Data Structures and Algorithms Graphs Single-Source Shortest Paths (Dijkstra’s Algorithm) PLSD210(ii)
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro.
Introduction to Algorithms 6.046J/18.401J/SMA5503
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
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.
CPSC 411, Fall 2008: Set 9 1 CPSC 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Fall 2008.
CS420 lecture twelve Shortest Paths wim bohm cs csu.
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 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.
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 Path Algorithms
Shortest Paths Definitions Single Source Algorithms
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
Analysis of Algorithms CS 477/677 Shortest Paths Instructor: George Bebis Chapter 24.
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
Notes This set of slides (Handout #7) is missing the material on Reductions and Greed that was presented in class. Those slides are still under construction,
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
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.
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
David Luebke 1 9/10/2015 CS 332: Algorithms Single-Source Shortest Path.
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.
David Luebke 1 9/10/2015 ITCS 6114 Single-Source Shortest Path.
David Luebke 1 9/13/2015 CS 332: Algorithms S-S Shortest Path: Dijkstra’s Algorithm Disjoint-Set Union Amortized Analysis.
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 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.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
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.
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.
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
1 Weighted Graphs. 2 Outline (single-source) shortest path –Dijkstra (Section 4.4) –Bellman-Ford (Section 4.6) (all-pairs) shortest path –Floyd-Warshall.
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
David Luebke 1 3/1/2016 CS 332: Algorithms Dijkstra’s Algorithm Disjoint-Set Union.
CSCE 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 9 1.
Single Source Shortest Paths Chapter 24 CSc 4520/6520 Fall 2013 Slides adapted from George Bebis, University of Reno, Nevada.
Shortest paths Given: A single source vertex (given s) in a weighted, directed graph. Want to compute a shortest path for each possible destination. (Single.
David Luebke 1 11/21/2016 CS 332: Algorithms Minimum Spanning Tree Shortest Paths.
Algorithms and Data Structures Lecture XIII
Minimum Spanning Tree Shortest Paths
CS200: Algorithm Analysis
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
CSC 413/513: Intro to Algorithms
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
CS 3013: DS & Algorithms Shortest Paths.
Presentation transcript:

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]) Single-source shortest-paths: find a shortest path from a source s to every vertex v  V Single pair shortest path problem asks for a u-v shortest path for some pair of vertices All pairs shortest-paths problem will be next time

Shortest Paths (25/24) Predecessor subgraph for restoring shortest paths Shortest-paths tree rooted at source s Th: Subpath of a shortest path is a shortest path Triangle Inequality:  (u,v)   (u,x) +  (x,v) Well defined: some paths may not exist if there is a negative-weight cycle in graph u x v <0

Bellman-Ford (25.3/24.1) Most basic (BFS based) algorithm, shortest paths (tree) easy to reconstruct. for each v  V do d[v]   ; d[s]  0 Relaxation for i =1,...,|V|-1 do for each edge (u,v)  E do d[v]  min{d[v], d[u]+w(u,v)} Negative cycle checking for each v  V do if d[v]> d[u] + w(u,v) then no solution Finally d[v]=  (s,v)

Bellman-Ford Analysis (25.3/24.1) Runtime = O(VE) Correctness –Lemma: d[v]   (s,v) Initially true Let d[v] = d[u] +w(u,v) by triangle inequality for first violation d[v] <  (s,v)   (s,u)+w(u,v)  d(u)+w(u,v) –After |V|-1 passes all d values are  ’s if there are no negative cycles s  v[1]  v[2] ...  v (some shortest path) After i-th iteration d[s,v[i]] is correct and final

Dag Shortest Paths (25.4/24.2) DAG shortest paths –Bellman-Ford = O(VE) –Topological sort O(V+E) (DFS) –Will never relaxed edges out of vertex v until have done all edges in v –Runtime O(V+E) Application: PERT ( program evaluation and review technique ) –Critical path is the longest path through the dag –Negating the edge weights and running dag shortest paths algorithm

Dijkstra’s Shortest Paths (25.2/24.3) Better than BF since non-negative weights. Like BFS but uses priority queue. for each v  V do d[v]   ; d[s]  0 S   ; Q  V While Q   do u  Extract-Min(Q) S  S + u for v adjacent to u do d[v]  min{d[v], d[u]+w(u,v)} (relaxation = Decrease-Key)

0          For each v  V do d[v] <-  ; d[s] <- 0 S <- , Q <- V a b g c d f e i h j

0  8       a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

0  8  28     a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

0  8     a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

  a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

  a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

a b g c d f e i h j While Q   do U Extract-Min(Q) S S + u for v adjacent to u do d[v] min{d[v], d[u]+w(u,v)}

Dijkstra’s Runtime (25.2/24.3) Extract-Min executed |V| times Decrease-Key executed |E| times Time = |V|  T(Extract-Min) (find+delete = O(log V)) + |E|  T(Decrease-Key) (delete+add =O(log V)) = Binary Heap = E  log V (30 years ago) = Fibonacci Heap = E + V  log V (10 years ago) Optimal time algorithm found 1/2 year ago. It runs in time O(E) (Mikel Thorup)

The same Lemma as for BF d[v]   (s,v) Th: Whenever u is added to S, d[u] =  (s,u) Let u be first s.t. d[u] >  (s,u) Let y be first  V-S on actual shortest s-u path  d[y] =  (s,y) For y’s predecessor x, d[x] =  (s,x) when put x in S d[y] gets  (s,y) d[u] >  (s,u) =  (s,y) +  (y,u) = d[y] +  (y,u)  d[y] Dijkstra’s Correctness (25.2/24.3) s x y u S Q