Lecture 12 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
Lecture 6 Shortest Path Problem. s t Dynamic Programming.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
1 Shortest Path Algorithms Given a graph G = (V, E) and a distinguished vertex s, find the shortest weighted path from s to every other vertex in G. weighted.
Chapter 7: Greedy Algorithms 7.4 Finding the Shortest Path Dijkstra’s Algorithm pp
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.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
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.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
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.
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.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
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.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Data Structures Week 9 Towards Weighted BFS So, far we have measured d s (v) in terms of number of edges in the path from s to v. Equivalent to assuming.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
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.
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.
Pathfinding Algorithms for Mutating Weight Graphs Haitao Mao Computer Systems Lab
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.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Graphs – Breadth First Search
COMP108 Algorithmic Foundations Greedy methods
Shortest Paths and Minimum Spanning Trees
Lecture 13 Shortest Path.
Graph Algorithms BFS, DFS, Dijkstra’s.
Minimum Spanning Trees
Chapter 7: Greedy Algorithms
Algorithms and Data Structures Lecture XIII
EMIS 8374 Dijkstra’s Algorithm Updated 18 February 2008
Lecture 6 Shortest Path Problem.
Shortest Path.
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
4.4 Shortest Paths in a Graph
CSE 373: Data Structures and Algorithms
Algorithms and Data Structures Lecture XIII
Dijkstra’s Shortest Path Algorithm Neil Tang 03/25/2008
Shortest Path Algorithms
Minimum Spanning Tree Algorithms
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Weighted Graphs & Shortest Paths
Dijkstra’s Shortest Path Algorithm Neil Tang 3/2/2010
Shortest Paths.
CSE 373 Data Structures and Algorithms
CSE 417: Algorithms and Computational Complexity
Implementation of Dijkstra’s Algorithm
Spanning Trees Lecture 20 CS2110 – Spring 2015.
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
Directed Graphs (Part II)
Data Structures and Algorithm Analysis Lecture 8
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Lecture 12 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.

Main step of proof Induction Hypothesis: At iteration i of Dijkstra’s algorithm, the algorithm correctly computes the shortest path to i visited vertices, and for any vertex v that is not visited, dis[v] is the length of shortest path to v that only uses visited vertices. u v s visited

Main step of proof Choosing the next vertex If v is the vertex with smallest dis[v], it cannot have a shorter path v’ v’’ u’ u v s visited

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)