CS 253: Algorithms Chapter 24 Shortest Paths Credit: Dr. George Bebis.

Slides:



Advertisements
Similar presentations
Chapter 23 Minimum Spanning Tree
Advertisements

October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Introduction To Algorithms CS 445 Discussion Session 6 Instructor: Dr Alon Efrat TA : Pooja Vaswani 03/21/2005.
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
Shortest Paths Algorithm Design and Analysis Week 7 Bibliography: [CLRS] – chap 24 [CLRS] – chap 25.
chapter Single-Source Shortest Paths Problem Definition Shortest paths and Relaxation Dijkstra’s algorithm (can be viewed as a greedy algorithm)
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,
Chapter 20: Graphs CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Chapter 25: All-Pairs Shortest-Paths
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
All Pairs Shortest Paths and Floyd-Warshall Algorithm CLRS 25.2
CS420 lecture twelve Shortest Paths wim bohm cs csu.
CSE 780 Algorithms Advanced Algorithms Shortest path Shortest path tree Relaxation Bellman-Ford Alg.
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 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.
1 Advanced Algorithms All-pairs SPs DP algorithm Floyd-Warshall alg.
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
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.
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.
All-Pairs Shortest Paths
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.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Dijkstra's algorithm.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
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.
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.
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.
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
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.
Lecture 13 Algorithm Analysis
All-Pairs Shortest Paths
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.
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 Trees
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
Lecture 13 Algorithm Analysis
Shortest Path Problems
Advanced Algorithms Analysis and Design
Single-Source Shortest Path & Minimum Spanning Trees
Presentation transcript:

CS 253: Algorithms Chapter 24 Shortest Paths Credit: Dr. George Bebis

2 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 graph: vertices = cities edges = road segments between cities edge weights = road distances ◦ Goal: find a shortest path between two vertices (cities)

Shortest Path Problem Input: ◦ Directed graph G = (V, E) ◦ Weight function w : E → R Weight of path p =  v 0, v 1,..., v k  Shortest-path weight from u to v : δ (u, v) = min w(p) : u v if there exists a path from u to v ∞ otherwise Note: there might be multiple shortest paths from u to v p s tx yz

4 Negative-Weight Edges Negative-weight edges may form negative-weight cycles If such cycles are reachable from the source, then δ (s, v) is not properly defined! ◦ Keep going around the cycle, and get w(s, v) = -  for all v on the cycle Therefore, negative-weight edges will not be considered here s ab ef -3 y c d g

Cycles Can shortest paths contain cycles? No! Negative-weight cycles ◦ Shortest path is not well defined (we will not consider this case) If there is a positive-weight cycle, we can get a shorter path by removing the cycle. Zero-weight cycles? ◦ No reason to use them ◦ Can remove them and obtain a path with the same weight

Shortest-Paths Notation For each vertex v  V: δ(s, v): shortest-path weight d[v]: shortest-path weight estimate ◦ Initially, d[v]=∞ ◦ d[v]  δ(s,v) as algorithm progresses  [v] = predecessor of v on a shortest path from s ◦ If no predecessor,  [v] = NIL ◦ induces a tree—shortest-path tree s tx yz

7 Initialization Alg.: INITIALIZE-SINGLE-SOURCE(V, s) 1. for each v  V 2. do d[v] ←  3.  [v] ← NIL 4. d[s] ← 0 All the shortest-paths algorithms start with INITIALIZE-SINGLE-SOURCE

Relaxation Step Relaxing an edge (u, v) = testing whether we can improve the shortest path to v found so far by going through u If d[v] > d[u] + w(u, v) we can improve the shortest path to v  d[v]=d[u]+w(u,v)   [v] ← u 59 2 uv 57 2 uv RELAX(u, v, w) 56 2 uv 56 2 uv After relaxation: d[v]  d[u] + w(u, v) ss no change

Dijkstra’s Algorithm Single-source shortest path problem: ◦ No negative-weight edges: w(u, v) > 0,  (u, v)  E Vertices in (V – S) reside in a min-priority queue ◦ Keys in Q are estimates of shortest-path weights d[u] Repeatedly select a vertex u  (V – S), with the minimum shortest-path estimate d[u] Relax all edges leaving u STEPS 1) Extract a vertex u from Q (i.e., u has the highest priority) 2) Insert u to S 3) Relax all edges leaving u 4) Update Q

10 Dijkstra (G, w, s) 0   s tx yz   s tx yz S=<> Q= S= Q=

Example (cont.) 0 10  5  s tx yz s tx yz S= Q=

Example (cont.) s tx yz s tx yz S= Q= S= Q=<>

Dijkstra (G, w, s) 1. INITIALIZE-SINGLE-SOURCE( V, s ) 2. S ← s 3. Q ← V[G] 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 ) 9. Update Q (DECREASE_KEY)  (V)  (V) build min-heap Executed  (V) times  (lgV)  (E) times (max)  (lgV)  (VlgV)  (ElgV) Running time:  (VlgV + ElgV) =  (ElgV)

Dijkstra’s SSSP Algorithm (adjacency matrix) b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] =  S new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] =   a b c d e f new L [.] =  SSSP cont. new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] =  a b c d e f new L [.] = new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] = a b c d e f new L [.] =

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] = a b c d e f new L [.] =

b a d c f e a b c d e f a   2 b   c  d   e   f 2    5 0 a b c d e f L [.] = a b c d e f new L [.] = Running time:  (V 2 ) (array representation)  (ElgV) (Min-Heap+Adjacency List) Which one is better?

All-Pairs Shortest Paths Given: Directed graph G = (V, E) Weight function w : E → R Compute: The shortest paths between all pairs of vertices in a graph Result: an n × n matrix of shortest-path distances δ(u, v) We can run Dijkstra’s algorithm once from each vertex: ◦ O(VElgV) with binary heap and adjacency-list representation ◦ if the graph is dense  O(V 3 lgV) ◦ We can achieve O(V 3 ) by using an adjacency-matrix

21 Problem 1 We are given a directed graph G=(V, E) on which each edge (u,v) has an associated value r(u,v), which is a real number in the range 0 ≤ r(u,v) ≤ 1 that represents the reliability of a communication channel from vertex u to vertex v. We interpret r(u,v) as the probability that the channel from u to v will not fail, and we assume that these probabilities are independent. Design an efficient algorithm to find the most reliable path between two given vertices.

22 Problem 1 (cont.) ◦ r(u,v) = Pr(channel from u to v will not fail) ◦ Assuming that the probabilities are independent, the reliability of a path p= is: r(v 1,v 2 ) r(v 2,v 3 ) … r(v k-1,v k ) Solution 1: modify Dijkstra’s algorithm ◦ Perform relaxation as follows: if d[v] < d[u] w(u,v) then d[v] = d[u] w(u,v) ◦ Use “EXTRACT_MAX” instead of “EXTRACT_MIN”

Problem 1 (cont.) Solution 2: use Dijkstra’s algorithm without any modifications! ◦ We want to find the channel with the highest reliability, i.e., ◦ But Dijkstra’s algorithm computes ◦ Take the log

Problem 1 (cont.) Turn this into a minimization problem by taking the negative: Run Dijkstra’s algorithm using