Graph Algorithms Shortest path problems. Graph Algorithms Shortest path problems.

Slides:



Advertisements
Similar presentations
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Advertisements

Advanced Algorithm Design and Analysis (Lecture 7) SW5 fall 2004 Simonas Šaltenis E1-215b
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=
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro.
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
Chapter 25: All-Pairs Shortest-Paths
All Pairs Shortest Paths and Floyd-Warshall Algorithm CLRS 25.2
CS420 lecture twelve Shortest Paths wim bohm cs csu.
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 8a-ShortestPathsMore Shortest Paths in a Graph (cont’d) Fundamental 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.
Graph Algorithms Shortest path problems [Adapted from K.Wayne]
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 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.
Analysis of Algorithms CS 477/677 Shortest Paths Instructor: George Bebis Chapter 24.
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
All-Pairs Shortest Paths
Lecture 8 Shortest Path Shortest-path problems
CS 253: Algorithms Chapter 24 Shortest Paths Credit: Dr. George Bebis.
Shortest Paths1 C B A E D F
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.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Topological Sorting and Least-cost Path Algorithms.
David Luebke 1 9/10/2015 CS 332: Algorithms Single-Source Shortest Path.
CISC 235: Topic 11 Shortest Paths Algorithms. CISC 235 Topic 112 Outline Single-Source Shortest Paths Algorithm for Unweighted Graphs Algorithm for Weighted,
David Luebke 1 9/13/2015 CS 332: Algorithms S-S Shortest Path: Dijkstra’s Algorithm Disjoint-Set Union Amortized Analysis.
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.
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.
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.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
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.
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.
Lecture 16. Shortest Path Algorithms
Minimum weight spanning trees
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)
Algorithms LECTURE 14 Shortest Paths II Bellman-Ford algorithm
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.
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.
Graph theory Prof Amir Geva Eitan Netzer.
Graphs Part II Lecture 7. Lecture Objectives  Topological Sort  Spanning Tree  Minimum Spanning Tree  Shortest Path.
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.
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.
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])
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
Greedy Technique.
SINGLE-SOURCE SHORTEST PATHS
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Lecture 11 Topics Application of BFS Shortest Path
Algorithms and Data Structures Lecture XIII
Chapter 24: Single-Source Shortest Paths
Chapter 24: Single-Source Shortest Paths
CS 3013: DS & Algorithms Shortest Paths.
Presentation transcript:

Graph Algorithms Shortest path problems

Graph Algorithms Shortest path problems

Graph Algorithms Shortest path problems

Graph Algorithms Single-Source Shortest Paths Given graph (directed or undirected) G = (V,E) with weight function w: E  R and a vertex s  V, find for all vertices v  V the minimum possible weight for path from s to v. We will discuss two general case algorithms: Dijkstra's (positive edge weights only) Bellman-Ford (positive end negative edge weights) If all edge weights are equal (let's say 1), the problem is solved by BFS in  (V+E) time.

Graph Algorithms Dijkstra’s Algorithm - Relax Relax(vertex u, vertex v, weight w) if d[v] > d[u] + w(u,v) then d[v]  d[u] + w(u,v) p[v]  u

Graph Algorithms Dijkstra’s Algorithm - Idea

Graph Algorithms Dijkstra’s Algorithm - SSSP-Dijkstra SSSP-Dijkstra(graph (G,w), vertex s) InitializeSingleSource(G, s) S   Q  V[G] while Q  0 do u  ExtractMin(Q) S  S  {u} for v  Adj[u] do Relax(u,v,w) InitializeSingleSource(graph G, vertex s) for v  V[G] do d[v]   p[v]  0 d[s]  0

Graph Algorithms Dijkstra’s Algorithm - Example

Graph Algorithms Dijkstra’s Algorithm - Example 0    

Graph Algorithms Dijkstra’s Algorithm - Example  

Graph Algorithms Dijkstra’s Algorithm - Example  

Graph Algorithms Dijkstra’s Algorithm - Example

Graph Algorithms Dijkstra’s Algorithm - Example

Graph Algorithms Dijkstra’s Algorithm - Example

Graph Algorithms Dijkstra’s Algorithm - Example

Graph Algorithms Dijkstra’s Algorithm - Example

Graph Algorithms Dijkstra’s Algorithm - Example

Graph Algorithms Dijkstra’s Algorithm - Complexity SSSP-Dijkstra(graph (G,w), vertex s) InitializeSingleSource(G, s) S   Q  V[G] while Q  0 do u  ExtractMin(Q) S  S  {u} for u  Adj[u] do Relax(u,v,w) InitializeSingleSource(graph G, vertex s) for v  V[G] do d[v]   p[v]  0 d[s]  0 Relax(vertex u, vertex v, weight w) if d[v] > d[u] + w(u,v) then d[v]  d[u] + w(u,v) p[v]  u  (V)  (1) ?  (E) times in total executed  (V) times

Graph Algorithms Dijkstra’s Algorithm - Complexity InitializeSingleSource T I (V,E) =  (V) Relax T R (V,E) =  (1)? SSSP-Dijkstra T(V,E) = T I (V,E) +  (V) + V  (log V) + E T R (V,E) = =  (V) +  (V) + V  (log V) + E  (1) =  (E + V log V)

Graph Algorithms Dijkstra’s Algorithm - Complexity

Graph Algorithms Dijkstra’s Algorithm - Correctness

Graph Algorithms Dijkstra’s Algorithm - negative weights?

Graph Algorithms Bellman-Ford Algorithm - negative cycles?

Graph Algorithms Bellman-Ford Algorithm - Idea

Graph Algorithms Bellman-Ford Algorithm - SSSP-BellmanFord SSSP-BellmanFord(graph (G,w), vertex s) InitializeSingleSource(G, s) for i  1 to |V[G]  1| do for (u,v)  E[G] do Relax(u,v,w) for (u,v)  E[G] do if d[v] > d[u] + w(u,v) then return false return true

Graph Algorithms Bellman-Ford Algorithm - Example

Graph Algorithms Bellman-Ford Algorithm - Example 0    

Graph Algorithms Bellman-Ford Algorithm - Example  

Graph Algorithms Bellman-Ford Algorithm - Example

Graph Algorithms Bellman-Ford Algorithm - Example

Graph Algorithms Bellman-Ford Algorithm - Example

Graph Algorithms Bellman-Ford Algorithm - Complexity SSSP-BellmanFord(graph (G,w), vertex s) InitializeSingleSource(G, s) for i  1 to |V[G]  1| do for (u,v)  E[G] do Relax(u,v,w) for (u,v)  E[G] do if d[v] > d[u] + w(u,v) then return false return true executed  (V) times  (E)  (1)

Graph Algorithms Bellman-Ford Algorithm - Complexity InitializeSingleSource T I (V,E) =  (V) Relax T R (V,E) =  (1)? SSSP-BellmanFord T(V,E) = T I (V,E) + V E T R (V,E) + E = =  (V) + V E  (1) + E = =  (V E)

Graph Algorithms Bellman-Ford Algorithm - Correctness

Graph Algorithms Bellman-Ford Algorithm - Correctness

Graph Algorithms Bellman-Ford Algorithm - Correctness

Graph Algorithms Bellman-Ford Algorithm - Correctness

Graph Algorithms Shortest Paths in DAGs - SSSP-DAG SSSP-DAG(graph (G,w), vertex s) topologically sort vertices of G InitializeSingleSource(G, s) for each vertex u taken in topologically sorted order do for each vertex v  Adj[u] do Relax(u,v,w)

Graph Algorithms Shortest Paths in DAGs - Example

Graph Algorithms Shortest Paths in DAGs - Example  0 

Graph Algorithms Shortest Paths in DAGs - Example  0 

Graph Algorithms Shortest Paths in DAGs - Example  0 

Graph Algorithms Shortest Paths in DAGs - Example 6 

Graph Algorithms Shortest Paths in DAGs - Example 664 

Graph Algorithms Shortest Paths in DAGs - Example 664 

Graph Algorithms Shortest Paths in DAGs - Example 654 

Graph Algorithms Shortest Paths in DAGs - Example 654 

Graph Algorithms Shortest Paths in DAGs - Example 653 

Graph Algorithms Shortest Paths in DAGs - Example 653 

Graph Algorithms Shortest Paths in DAGs - Complexity T(V,E) =  (V + E) +  (V) +  (V) + E  (1) =  (V + E) SSSP-DAG(graph (G,w), vertex s) topologically sort vertices of G InitializeSingleSource(G, s) for each vertex u taken in topologically sorted order do for each vertex v  Adj[u] do Relax(u,v,w)

Graph Algorithms Application of SSSP - currency conversion

Graph Algorithms Application of SSSP - currency conversion

Graph Algorithms Application of SSSP - currency conversion

Graph Algorithms Application of SSSP - constraint satisfaction

Graph Algorithms Application of SSSP - constraint satisfaction

Graph Algorithms Application of SSSP - constraint satisfaction

Graph Algorithms Application of SSSP - constraint satisfaction

Graph Algorithms Application of SSSP - constraint satisfaction

Graph Algorithms Application of SSSP - constraint satisfaction

Graph Algorithms All-Pairs Shortest Paths Given graph (directed or undirected) G = (V,E) with weight function w: E  R find for all pairs of vertices u,v  V the minimum possible weight for path from u to v.

Graph Algorithms Floyd-Warshall Algorithm - Idea

Graph Algorithms Floyd-Warshall Algorithm - Idea

Graph Algorithms Floyd-Warshall Algorithm - Idea d s,t (i) – the shortest path from s to t containing only vertices v 1,..., v i d s,t (0) = w(s,t) d s,t (k) = w(s,t)if k = 0 min{d s,t (k-1), d s,k (k-1) + d k,t (k-1) }if k > 0

Graph Algorithms Floyd-Warshall Algorithm - Algorithm FloydWarshall(matrix W, integer n) for k  1 to n do for i  1 to n do for j  1 to n do d ij (k)  min(d ij (k-1), d ik (k-1) + d kj (k-1) ) return D (n)

Graph Algorithms Floyd-Warshall Algorithm - Example  -4  0  17  40  2  -50   60 W

Graph Algorithms Floyd-Warshall Algorithm - Example 038  -4  0  17  40  2  -50   D (0)  (0)

Graph Algorithms Floyd-Warshall Algorithm - Example 038  -4  0  17  40   D (1)  (1)

Graph Algorithms Floyd-Warshall Algorithm - Example  0  17   D (2)  (2)

Graph Algorithms Floyd-Warshall Algorithm - Example  0  17   D (3)  (3)

Graph Algorithms Floyd-Warshall Algorithm - Example D (4)  (4)

Graph Algorithms Floyd-Warshall Algorithm - Example D (5)  (5)

Graph Algorithms Floyd-Warshall Algorithm - Extracting the shortest paths

Graph Algorithms Floyd-Warshall Algorithm - Complexity T(V,E) =  (n 3 ) =  (V 3 ) FloydWarshall(matrix W, integer n) for k  1 to n do for i  1 to n do for j  1 to n do d ij (k)  min(d ij (k-1), d ik (k-1) + d kj (k-1) ) return D (n) 3 for cycles, each executed exactly n times

Graph Algorithms All-Pairs Shortest Paths -Johnson's algorithm

Graph Algorithms All-Pairs Shortest Paths - Reweighting

Graph Algorithms All-Pairs Shortest Paths - Reweighting

Graph Algorithms All-Pairs Shortest Paths - Reweighting