1 2 3 4 6 5 10 1 5 4 3 31 2 6 1 1 8 Graph Algorithms: Shortest Path We are given a weighted, directed graph G = (V, E), with weight function w: E R mapping.

Slides:



Advertisements
Similar presentations
Single Source Shortest Paths
Advertisements

The Greedy Approach Chapter 8. The Greedy Approach It’s a design technique for solving optimization problems Based on finding optimal local solutions.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CS138A Single Source Shortest Paths Peter Schröder.
chapter Single-Source Shortest Paths Problem Definition Shortest paths and Relaxation Dijkstra’s algorithm (can be viewed as a greedy algorithm)
Applications Data Structures and Algorithms (60-254)
CSE 101- Winter ‘15 Discussion Section January 26th 2015.
Introduction to Algorithms 6.046J/18.401J/SMA5503
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
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.
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.1 Data Structure and Algorithm Lecture 11 Application of BFS  Shortest Path Topics Reference: Introduction to Algorithm by Cormen Chapter 25: Single-Source.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
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)
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.
Shortest Path Algorithms
Shortest Paths Definitions Single Source Algorithms
DAST 2005 Tirgul 12 (and more) sample questions. DAST 2005 Q.We’ve seen that solving the shortest paths problem requires O(VE) time using the Belman-Ford.
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
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.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
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.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Dijkstra's algorithm.
Topological Sorting and Least-cost Path Algorithms.
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.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 8 Greedy Graph.
CISC 235: Topic 11 Shortest Paths Algorithms. CISC 235 Topic 112 Outline Single-Source Shortest Paths Algorithm for Unweighted Graphs Algorithm for Weighted,
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.
CS223 Advanced Data Structures and Algorithms 1 The Bellman-Ford Shortest Path Algorithm Neil Tang 03/11/2010.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
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.
Dijkstra’s Algorithm Supervisor: Dr.Franek Ritu Kamboj
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)
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
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.
Lecture 13 Algorithm Analysis
Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,
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.
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])
Minimum Spanning Tree Shortest Paths
SINGLE-SOURCE SHORTEST PATHS
Announcement 2: A 2 hour midterm (open book) will be given on March (Tuesday) during the lecture time. 2018/12/4.
Page 620 Single-Source Shortest Paths
2018/12/27 chapter25.
Advanced Algorithms Analysis and Design
Lecture 11 Topics Application of BFS Shortest Path
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Slide Courtesy: Uwash, UT
Lecture 13 Algorithm Analysis
Brad Karp UCL Computer Science
Slide Courtesy: Uwash, UT
Graph Algorithms: Shortest Path
CSE 417: Algorithms and Computational Complexity
CS 3013: DS & Algorithms Shortest Paths.
Single-Source Shortest Path & Minimum Spanning Trees
Presentation transcript:

Graph Algorithms: Shortest Path We are given a weighted, directed graph G = (V, E), with weight function w: E R mapping edges to real valued weights. The weight of a path p = (v, v,..., v ) is  w(v, v ). 12k i=1 k-1 ii+1 The weight of the path along the red edges is = 12. Single source shortest path problem: given a vertex s, for every vertex v  V find a shortest path from s to v.

Graph Algorithms: Shortest Path Dijkstra’s algorithm maintains a set S of vertices whose final shortest path weights have already been determined. It also maintains, for each vertex v not in S, an upper bound d[v] on the weight of a shortest path from source s to v. Dijkstra’s algorithm solves this problem efficiently for the case in which all weights are nonnegative (as in the example graph). The algorithm repeatedly selects the vertex u  V – S with minimum bound d[u], inserts u into S, and relaxes all edges leaving u (determines if passing through u makes it “faster” to get to a vertex adjacent to u).

Graph Algorithms: Shortest Path Dijkstra’s algorithm maintains a set S of vertices whose final shortest path weights have already been determined. s Set S = { } initially v d[v]d[v] Also initialize a queue with all the vertices and their upper bounds. Suppose vertex 1 is the source.

Graph Algorithms: Shortest Path s v S = (here we keep the bound with the vertex in S) Remove from the queue the vertex u  V – S with minimum bound d[u], insert u into S,... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source.... and relax the edges from this vertex. 1 0 d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source.... reordering the queue according to the new upper bounds. 1 0 d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source. Repeat d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source.... remove from queue and put in S d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source.... relax the edges d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source.... and reorder the queue d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source Repeat... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source remove from queue and put in S d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source relax the edges... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source and reorder the queue... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source Repeat... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source remove from queue and put in S d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source relax the edges (no change in this case)... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source and reorder the queue (no change in this case)... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source Repeat... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source remove from queue and put in S d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source relax the edges (no change in this case)... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source Repeat... d[v]d[v]

Graph Algorithms: Shortest Path s S = v Suppose vertex 1 is the source Done! d[v]d[v]

Graph Algorithms: Shortest Path Dijkstra’s algorithm maintains a set S of vertices whose final shortest path weights have already been determined. s S = Suppose vertex 1 is the source. The result is the bottom row which contains the length of the shortest path from s to the vertex above it. v d[v]d[v]

Graph Algorithms: Shortest Path s S = To compute the corresponding paths, we augment the data structure with an additional attribute, p[v], which is the vertex that precedes v in a shortest path. v p[v]p[v] d[v]d[v]

Graph Algorithms: Shortest Path s S = Using the predecessor attribute, p[v], it’s easy to construct the path to v, working backwards from v to s. v p[v]p[v] d[v]d[v]

Graph Algorithms: Shortest Path s S = E.g., v = 6. v p[v]p[v] d[v]d[v]

Graph Algorithms: Shortest Path s S = E.g., v = 6. p[6] = 5, v d[v]d[v] p[v]p[v]

Graph Algorithms: Shortest Path s S = E.g., v = 6. p[6] = 5, p[5] = 3, v d[v]d[v] p[v]p[v]

Graph Algorithms: Shortest Path s S = E.g., v = 6. p[6] = 5, p[5] = 3, p[3] = 1. v d[v]d[v] p[v]p[v]

Graph Algorithms: Shortest Path s S = E.g., v = 6. p[6] = 5, p[5] = 3, p[3] = 1. v Path: 1, 3, 5, 6. Weight: 4. d[v]d[v] p[v]p[v]

Graph Algorithms: Shortest Path PseudoCode Notes: - G is a directed, weighted graph with nonnegative edge weights - Edges of G are represented using an Adjacency List - Q is a Priority Queue. Current distance upper bound (d) is key value in Q DIJKSTRA(G,w,s) INITIALIZE-SINGLE-SOURCE(G,s) S 0 Q V[G] while Q = 0 do u EXTRACT-MIN(Q) S S U {u} for each vertex v in AdjList[u] do RELAX(u,v,w)

Priority queue T T Total time Unsorted Array O(|V|) O(1) O(V 2 + E) = O(V 2 ) Binary heap O(log |V|) O(log |V|) O((V+E) log |V|) = O(E log |V|) EXTRACT-MIN DECREASE-KEY Graph Algorithms: Shortest Path Computing time analysis: look at different implementations of the priority queue, with different costs for the queue operations. EXTRACT-MIN executed how many times? EXTRACT-MIN executed |V| times. DECREASE-KEY is called by RELAX DECREASE-KEY executed how many times? DECREASE-KEY executed total of |E| times. Total time = |V| T + |E| T EXTRACT-MIN DECREASE-KEY