Dijkstra’s Algorithm SSSP, non-neg Edge weights = w(x,y)

Slides:



Advertisements
Similar presentations
Bellman-Ford algorithm
Advertisements

1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine.
Graph Algorithms - 3 Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 13Feb 12, 2014Carnegie Mellon University.
Surender Baswana Department of CSE, IIT Kanpur. Surender Baswana Department of CSE, IIT Kanpur.
Single Source Shortest Paths
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
CS420 lecture twelve Shortest Paths wim bohm cs csu.
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.
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.
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
MIKKEL THORUP 1999 Journal of the ACM Undirected Single-Source Shortest Paths with Positive Integer Weights in Linear Time.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Dynamic Single-source Shortest Paths Camil Demetrescu University of Rome “La Sapienza”
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Graph (II) Shortest path, Minimum spanning tree GGuy
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
Shortest Paths and Dijkstra’s Algorithm CS 105. SSSP Slide 2 Single-source shortest paths Given a weighted graph G and a source vertex v in G, determine.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Shortest Paths.
Shortest Paths.
Shortest Paths and Minimum Spanning Trees
Lecture 13 Shortest Path.
CSC317 Shortest path algorithms
Single-Source Shortest Path
Graph Algorithms BFS, DFS, Dijkstra’s.
Shortest Path Problems
All-Pairs Shortest Paths (26.0/25)
Chapter 25: All-Pairs Shortest Paths
Shortest Paths.
Lecture 7 Shortest Path Shortest-path problems
Shortest paths & Weighted graphs
CS200: Algorithm Analysis
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Shortest-Paths Trees Kun-Mao Chao (趙坤茂)
Topic 13 Graphs 2.
Lecture 11 Topics Application of BFS Shortest Path
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Shortest Path Algorithms
Analysis of Algorithms
Shortest Paths and Minimum Spanning Trees
Floyd’s Algorithm (shortest-path problem)
Lecture 13 Algorithm Analysis
Advanced Algorithms Analysis and Design
Lecture 13 Algorithm Analysis
Honors Track: Competitive Programming & Problem Solving Avoiding negative edges Steven Ge.
The Bellman-Ford Shortest Path Algorithm Neil Tang 03/27/2008
Algorithms: Design and Analysis
Chapter 24: Single-Source Shortest Paths
Shortest Path Problems
Autumn 2016 Lecture 10 Minimum Spanning Trees
Shortest Path Problems
Graph Algorithms: Shortest Path
Shortest Paths.
Chapter 24: Single-Source Shortest Paths
Lecture 12 Shortest Path.
CS 3013: DS & Algorithms Shortest Paths.
Winter 2019 Lecture 10 Minimum Spanning Trees
Chapter 24: Single-Source Shortest-Path
All Pairs Shortest Path Examples While the illustrations which follow only show solutions from vertex A (or 1) for simplicity, students should note that.
Analysis of Algorithms
Premaster Course Algorithms 1 Chapter 6: Shortest Paths
Data Structures and Algorithm Analysis Lecture 8
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Dijkstra’s Algorithm SSSP, non-neg Edge weights = w(x,y) Final distances = d(x,y) = dw(x,y) b 2 2 e s 2 6 2 c 6 1 d

Dijkstra’s Algorithm SSSP, non-neg s b c d e ∞ L(x) b 2 2 e s 2 6 2 c ∞ L(x) b 2 2 e s 2 6 2 c x <- extractmin 6 1 // L(x) is the distance of s to x // mark x as final d "relax” all the edges out of x L(y) <- min ( L(y), L(x) + w(x,y) )

Dijkstra’s Algorithm SSSP, non-neg s b c d e 2 6 ∞ L(x) b 2 2 e s 2 6 2 6 ∞ L(x) b 2 2 e s 2 6 2 c x <- extractmin 6 1 // L(x) is the distance of s to x // mark x as final d "relax” all the edges out of x L(y) <- min ( L(y), L(x) + w(x,y) )

Dijkstra’s Algorithm SSSP, non-neg s b c d e 2 4 6 L(x) b 2 2 e s 2 6 2 4 6 L(x) b 2 2 e s 2 6 2 c x <- extractmin 6 1 // L(x) is the distance of s to x // mark x as final d "relax” all the edges out of x L(y) <- min ( L(y), L(x) + w(x,y) )

Dijkstra’s Algorithm SSSP, non-neg s b c d e 2 4 6 L(x) b 2 2 e s 2 6 2 4 6 L(x) b 2 2 e s 2 6 2 c x <- extractmin 6 1 // L(x) is the distance of s to x // mark x as final d "relax” all the edges out of x L(y) <- min ( L(y), L(x) + w(x,y) )

Dijkstra’s Algorithm SSSP, non-neg s b c d e 2 4 5 L(x) b 2 2 e s 2 6 2 4 5 L(x) b 2 2 e s 2 6 2 c x <- extractmin 6 1 // L(x) is the distance of s to x // mark x as final d "relax” all the edges out of x L(y) <- min ( L(y), L(x) + w(x,y) )

Dijkstra’s Algorithm SSSP, non-neg m decreasekeys n extractmins Fib heap: O(m + n log n) s b c d e 2 4 5 L(x) b 2 2 e s 2 6 2 c x <- extractmin 6 1 // L(x) is the distance of s to x // mark x as final d "relax” all the edges out of x L(y) <- min ( L(y), L(x) + w(x,y) )

Bellman-Ford-Moore Algorithm SSSP, neg wts OK

Bellman-Ford-Moore Algorithm SSSP, neg wts OK n rounds m time per round O(mn) time s b c d e ∞ L(x) // L(x) is an upper bound on d(s,x) b 2 2 e for t = 1 to n-1 s 2 6 -2 for all vertices x c // "relax” all the edges out of x 6 1 L(y) <- min ( L(y), L(x) + w(x,y) ) d Claim: if graph has non negative cycles, B-F-M is OK. Proof: induction. At end of round t, L(y) is shortest path using at most t edges.

Bellman-Ford-Moore Algorithm SSSP, neg wts OK n rounds m time per round O(mn) time s b c d e 2 5 4 L(x) // L(x) is an upper bound on d(s,x) b 2 2 e for t = 1 to n-1 s 2 6 -2 for all vertices x c // "relax” all the edges out of x 6 1 L(y) <- min ( L(y), L(x) + w(x,y) ) d Claim: if graph has non negative cycles, B-F-M is OK. Proof: induction. At end of round t, L(y) is shortest path using at most t edges.

Bellman-Ford-Moore Algorithm SSSP, neg wts OK n rounds m time per round O(mn) time s b c d e 2 5 4 L(x) // L(x) is an upper bound on w(s,x) b 2 2 e for t = 1 to n-1 s 2 6 -2 for all vertices x c // "relax” all the edges out of x 6 1 L(y) <- min ( L(y), L(x) + w(x,y) ) d Claim: If at end, some edge xy is “over-tight” ( it has L(y) > L(x) + w(x,y) ) then graph has negative cycle.

Lots more work! E.g., extensions and implementations of (just) Dijkstra’s algorithm: slide from Mikkel Thorup

All Pairs SP Non-neg weights: n Dijkstras O(mn + n2 log n) n B-F-M O(mn2)

Johnson’s Algorithm APSP, neg wts OK Find “feasible potentials” ©(x) such that the “reduced weights” ŵ(x,y) := ©(x) + w(x,y) - ©(y) ≥ 0 Fact: reduced weights ŵ non-neg Claim: dw (x,y) = dŵ(x,y) + ©(y) - ©(x) b 2 2 So shortest paths don’t change, though their weights might.  suffices to find APSP in this non-neg weights graph! e s 2 6 -2 c 6 1 How to find these “feasible potentials”? d

Johnson’s Algorithm APSP, neg wts OK Find “feasible potentials” ©(x) such that the “reduced weights” ŵ(x,y) := ©(x) + w(x,y) - ©(y) ≥ 0 Fact: reduced weights ŵ non-neg Claim: dw (x,y) = dŵ(x,y) + ©(y) - ©(x) b 2 2 So shortest paths don’t change, though their weights might.  suffices to find APSP in this non-neg weights graph! e s 2 6 -2 c 6 1 How to find these “feasible potentials”? d Shortest paths from Z. No negative cycles created, so B-F-M works. Z

All Pairs SP Non-neg weights: n Dijkstras O(mn + n2 log n) n B-F-M O(mn2) Neg weights: B-F-M + n Dijkstras O(mn + n2 log n) Neg weights: Floyd-Warshall O(n3) for all vertices z for all vertices x,y d(x,y) <- min{ d(x,y), d(x,z) + d(z,y)

All Pairs SP Non-neg weights: n Dijkstras O(mn + n2 log n) n B-F-M O(mn2) Neg weights: B-F-M + n Dijkstras O(mn + n2 log n) Neg weights: Floyd-Warshall O(n3) Neg weights: Naïve Min-Sum-Product O(n3 log n)