CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths.

Slides:



Advertisements
Similar presentations
Bellman-Ford algorithm
Advertisements

 Theorem 5.9: Let G be a simple graph with n vertices, where n>2. G has a Hamilton circuit if for any two vertices u and v of G that are not adjacent,
1 Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Single Source Shortest Paths
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
CSEP 521 Applied Algorithms Richard Anderson Lecture 7 Dynamic Programming.
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 38 CSE 331 Dec 7, The last few days Today: Solutions to HW 9 (end of lecture) Wednesday: Graded HW 9 (?), Sample final, Blog post on the.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
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.
CSE 421 Algorithms Richard Anderson Dijkstra’s algorithm.
Lecture 39 CSE 331 Dec 6, On Friday, Dec 10 hours-a-thon Atri: 2:00-3:30 (Bell 123) Jeff: 4:00-5:00 (Bell 224) Alex: 5:00-6:30 (Bell 242)
Shortest Path Algorithm By Weston Vu CS 146. What is Shortest Paths? Shortest Paths is a part of the graph algorithm. It is used to calculate the shortest.
CSE 421 Algorithms Richard Anderson Lecture 10 Minimum Spanning Trees.
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
Lecture 39 CSE 331 Dec 9, Announcements Please fill in the online feedback form Sample final has been posted Graded HW 9 on Friday.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
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.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 22.
10/4/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 17 Dynamic.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 17.
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.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Lecture 38 CSE 331 Dec 2, Review Sessions etc. Atri: (at least ½ of) class next Friday Jiun-Jie: Extra office hour next Friday Jesse: Review Session.
CS38 Introduction to Algorithms Lecture 10 May 1, 2014.
Lecture 38 CSE 331 Dec 5, OHs today (only online 9:30-11)
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
CSE 421 Algorithms Richard Anderson Lecture 8 Optimal Caching Dijkstra’s algorithm.
CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths and Network Flow.
TIRGUL 10 Dijkstra’s algorithm Bellman-Ford Algorithm 1.
Lecture 13 Shortest Path.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Shortest Paths with Dynamic Programming
Chapter 6 Dynamic Programming
Shortest paths & Weighted graphs
Autumn 2016 Lecture 9 Dijkstra’s algorithm
Autumn 2015 Lecture 9 Dijkstra’s algorithm
CSE 373: Data Structures and Algorithms
Richard Anderson Lecture 20 LCS / Shortest Paths
Richard Anderson Lecture 11 Minimum Spanning Trees
Richard Anderson Lecture 9 Dijkstra’s algorithm
Richard Anderson Lecture 9 Dijkstra’s algorithm
Autumn 2015 Lecture 10 Minimum Spanning Trees
Richard Anderson Lecture 21 Shortest Path Network Flow Introduction
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Chapter 6 Dynamic Programming
Richard Anderson Lecture 21 Network Flow
Richard Anderson Lecture 21 Shortest Paths
Slide Courtesy: Uwash, UT
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Evaluation of the Course (Modified)
Lecture 21 Network Flow, Part 1
Autumn 2016 Lecture 10 Minimum Spanning Trees
CSE 373 Data Structures and Algorithms
Slide Courtesy: Uwash, UT
Richard Anderson Lecture 22 Network Flow
Winter 2019 Lecture 9 Dijkstra’s algorithm
CSE 417: Algorithms and Computational Complexity
Richard Anderson Lecture 20 Shortest Paths and Network Flow
Richard Anderson Lecture 5 Graph Theory
Winter 2019 Lecture 10 Minimum Spanning Trees
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Richard Anderson Lecture 22 Network Flow
Richard Anderson Lecture 20 Space Efficient LCS
Memory Efficient Dynamic Programming / Shortest Paths
Autumn 2019 Lecture 9 Dijkstra’s algorithm
Presentation transcript:

CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths

Shortest Path Problem Dijkstra’s Single Source Shortest Paths Algorithm –O(mlog n) time, positive cost edges General case – handling negative edges If there exists a negative cost cycle, the shortest path is not defined Bellman-Ford Algorithm –O(mn) time for graphs with negative cost edges

Lemma If a graph has no negative cost cycles, then the shortest paths are simple paths Shortest paths have at most n-1 edges

Shortest paths with a fixed number of edges Find the shortest path from v to w with exactly k edges

Express as a recurrence Opt k (w) = min x [Opt k-1 (x) + c xw ] Opt 0 (w) = 0 if v=w and infinity otherwise

Algorithm, Version 1 foreach w M[0, w] = infinity; M[0, v] = 0; for i = 1 to n-1 foreach w M[i, w] = min x (M[i-1,x] + cost[x,w]);

Algorithm, Version 2 foreach w M[0, w] = infinity; M[0, v] = 0; for i = 1 to n-1 foreach w M[i, w] = min(M[i-1, w], min x (M[i-1,x] + cost[x,w]))

Algorithm, Version 3 foreach w M[w] = infinity; M[v] = 0; for i = 1 to n-1 foreach w M[w] = min(M[w], min x (M[x] + cost[x,w]))

Correctness Proof for Algorithm 3 Key lemma – at the end of iteration i, for all w, M[w] <= M[i, w]; Reconstructing the path: –Set P[w] = x, whenever M[w] is updated from vertex x

If the pointer graph has a cycle, then the graph has a negative cost cycle If P[w] = x then M[w] >= M[x] + cost(x,w) –Equal when w is updated –M[x] could be reduced after update Let v 1, v 2,…v k be a cycle in the pointer graph with (v k,v 1 ) the last edge added –Just before the update M[v j ] >= M[v j+1 ] + cost(v j+1, v j ) for j < k M[v k ] > M[v 1 ] + cost(v 1, v k ) –Adding everything up 0 > cost(v 1,v 2 ) + cost(v 2,v 3 ) + … + cost(v k, v 1 ) v2v2 v3v3 v1v1 v4v4

Negative Cycles If the pointer graph has a cycle, then the graph has a negative cycle Therefore: if the graph has no negative cycles, then the pointer graph has no negative cycles

Finding negative cost cycles What if you want to find negative cost cycles?

Foreign Exchange Arbitrage USDEURCAD USD EUR CAD USD CADEUR USD CADEUR