Lecture 13 Shortest Path.

Slides:



Advertisements
Similar presentations
Bellman-Ford algorithm
Advertisements

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.
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
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source 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.
Shortest Paths Definitions Single Source Algorithms
Nondecreasing Paths in Weighted Graphs Or: How to optimally read a train schedule Virginia Vassilevska.
All-Pairs Shortest Paths
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Dijkstra's algorithm.
SPANNING TREES Lecture 21 CS2110 – Spring
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
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,
TIRGUL 10 Dijkstra’s algorithm Bellman-Ford Algorithm 1.
School of Computing Clemson University Fall, 2012
Shortest Paths.
COMP108 Algorithmic Foundations Greedy methods
Shortest Paths and Minimum Spanning Trees
Graph Algorithms BFS, DFS, Dijkstra’s.
Minimum Spanning Trees
Chapter 7: Greedy Algorithms
Discrete Optimization Lecture 1
Algorithms and Data Structures Lecture XIII
Introduction to Graphs
Shortest Path Problems
Shortest Path Problems
All-Pairs Shortest Paths (26.0/25)
Shortest Paths C B A E D F Shortest Paths
Shortest Paths.
Lecture 6 Shortest Path Problem.
Algorithms (2IL15) – Lecture 5 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
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Autumn 2015 Lecture 10 Minimum Spanning Trees
Dijkstra’s Shortest Path Algorithm Neil Tang 03/25/2008
Shortest Path Problems
Shortest Path Algorithms
Shortest Paths and Minimum Spanning Trees
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Fundamental Data Structures and Algorithms
Algorithms (2IL15) – Lecture 7
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
The Bellman-Ford Shortest Path Algorithm Neil Tang 03/27/2008
Algorithms: Design and Analysis
Weighted Graphs & Shortest Paths
Autumn 2016 Lecture 10 Minimum Spanning Trees
Shortest Paths.
Shortest Path Problems
Shortest Paths.
CSE 417: Algorithms and Computational Complexity
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Lecture 12 Shortest Path.
CS 3013: DS & Algorithms Shortest Paths.
Winter 2019 Lecture 10 Minimum Spanning Trees
Lecture 14 Minimum Spanning Tree (cont’d)
Chapter 24: Single-Source Shortest-Path
Single-Source Shortest Path & Minimum Spanning Trees
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Data Structures and Algorithm Analysis Lecture 8
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Lecture 13 Shortest Path

Shortest Path problem Given a graph G, edges have length w(u,v) > 0. (distance, travel time, cost, … ) Length of a path is equal to the sum of edge lengths Goal: Given source s and destination t, find the paths with minimum length.

Designing the algorithm What properties do shortest paths have? Claim: Given a shortest paths from s to t, any sub-path is still a shortest path between its two end-points. Which basic design technique has this property? … …

Shortest Path by Dynamic Programming Problem: Graph may have cycle. What ordering do I use? Length of last step Shortest Path to a Predecessor

Dijkstra’s algorithm Main idea: The correct ordering is an ascending order of distance from source. Intuition: To get to a point v, if the last step of shortest path is (u, v), then u should always be closer to s than v.  If I have computed shortest paths for all vertices that are closer to s than v, then I’m ready to compute shortest paths to v.

Dijkstra’s algorithm Dijkstra(s) initialize dis[u] to be all infinity, prev[u] to be NULL For neighbors of s, initialize dis[u] = w[s,u], prev[u] = s Mark s as visited FOR i = 2 to n Among all vertices that are not visited, find the one with smallest distance, call it u. Mark u as visited FOR all edges (u,v) IF dis[u]+w[u,v] < dis[v] THEN dis[v] = dis[u]+w[u,v] prev[v] = u.

Running time To analyze the running time of a graph algorithm, usually we want to analyze what is the average amount of time spent on each edge/vertex For Dijkstra We need to find the closest vertex n times. We need to update weight of edges m times. Naïve implementation: O(n) per vertex, O(1) per edge Use a binary heap: O(log n) per vertex and edge. Best: Use Fibonacci heap, O(log n) per vertex, O(1) per edge. Total runtime = O(m + nlog n)

Shortest Path with negative edge length What is w(u,v) can be negative? Motivation: Arbitrage Image from wikipedia

Modeling arbitrage Suppose u, v are different currency, exchange rate is C(u,v) (1 unit of v is worth C(u,v) units of u) Let length of edge w(u,v) = log C(u,v) Length of a path = log of the total exchange rate Shortest path = best way to exchange money. Negative cycle = arbitrage.

How to compute shortest path with negative edges? Claim: Given a shortest paths from s to t, any sub-path is still a shortest path between its two end-points. Is this still true? Dijkstra: If I have computed shortest paths for all vertices that are closer to s than v, then I’m ready to compute shortest paths to v.

Approach: dynamic programming with steps Bellman Ford algorithm: d[u, i] = length of shortest path to get to u with i steps 𝑑 𝑣,𝑖+1 = min 𝑢,𝑣 ∈𝐸 𝑤 𝑢,𝑣 +𝑑(𝑢,𝑖) Question: How many steps do we need to take? Length of last step Shortest Path to a Predecessor