Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Greed: Shortest Path s 3 t 2 6 7 4 5 23 18 2 9 14 15 5 30 20 44 16 11 6 19 6.

Slides:



Advertisements
Similar presentations
Thursday, March 14 Introduction to Network Flows
Advertisements

Advanced Algorithm Design and Analysis Jiaheng Lu Renmin University of China
Single Source Shortest Paths
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
November 14, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Aalborg University
Introduction to Algorithms 6.046J/18.401J/SMA5503
Shortest Paths1 C B A E D F
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.
Computational Methods for Management and Economics Carla Gomes Module 9a Network Models Terminology (Slides adapted from J.Orlin’s)
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.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
Shortest Paths Definitions Single Source Algorithms
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
COS 423 Lecture 9 Shortest Paths II ©Robert E. Tarjan 2011.
Lecture 8 Shortest Path Shortest-path problems
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Shortest Paths1 C B A E D F
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Binary and Binomial Heaps These lecture slides are adapted from CLRS, Chapters.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
Graph Theory Chapter 6 from Johnsonbaugh Article(6.1, 6.2)
David Luebke 1 9/10/2015 CS 332: Algorithms Single-Source Shortest Path.
David Luebke 1 9/10/2015 ITCS 6114 Single-Source Shortest Path.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 8 Greedy Graph.
David Luebke 1 9/13/2015 CS 332: Algorithms S-S Shortest Path: Dijkstra’s Algorithm Disjoint-Set Union Amortized Analysis.
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.
Maximum Flow Chapter 26.
. 1 Transportation and Assignment Problems. . 2 Applications Physical analog of nodes Physical analog of arcs Flow Communication systems phone exchanges,
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 7 Greedy Graph.
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.
Lecture 16. Shortest Path Algorithms
Introduction to Algorithms Jiafen Liu Sept
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.
Graphs Discrete Structure CS203. Adjacency Matrix We already saw a way of representing relations on a set with a Boolean matrix: R digraph(R) M R1234.
Overview of Graph Theory. Some applications of Graph Theory Models for communications and electrical networks Models for computer architectures Network.
1 Introduction to Algorithms L ECTURE 17 (Chap. 24) Shortest paths I 24.2 Single-source shortest paths 24.3 Dijkstra’s algorithm Edsger Wybe Dijkstra
Lecture 13 Algorithm Analysis
Shortest Path Algorithm 2 Prof. Sin-Min Lee Department of Computer Science.
Taken from Kevin Wayne’s slides (Princeton University) COSC 3101A - Design and Analysis of Algorithms 13 Maximum Flow.
1 Chapter 5-2 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Sections 2.5 and 4.4 Priority Queues and Dijkstra’s Algorithm For Shortest Paths Some Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley.
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
CSCE 3110 Data Structures & Algorithm Analysis Graphs (I) Reading: Chap.9, Weiss.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 10.
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])
Maximum Flow Chapter 26.
Algorithms and Data Structures Lecture XIII
Minimum Spanning Tree Shortest Paths
Max Flow – Min Cut Problem
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Shortest Paths C B A E D F Shortest Paths
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
4.4 Shortest Paths in a Graph
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
CSC 413/513: Intro to Algorithms
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Graph Algorithms: Shortest Path
CSE 417: Algorithms and Computational Complexity
CS 3013: DS & Algorithms Shortest Paths.
Data Structures and Algorithm Analysis Lecture 8
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Greed: Shortest Path s 3 t

Directed Graph Directed graph: G = (V, E). n V = set of vertices or nodes. n E  V  V = set of edges or arcs. n n = |V|, m = |E|. n Directed path: s t. – simple n Directed cycle:

3 Networks communication Network telephone exchanges, computers, satellites NodesArcs cables, fiber optics, microwave relays Flow voice, video, packets circuits gates, registers, processors wirescurrent mechanicaljointsrods, beams, springsheat, energy hydraulic reservoirs, pumping stations, lakes pipelinesfluid, oil financialstocks, currencytransactionsmoney transportation airports, rail yards, street intersections highways, railbeds, airway routes freight, vehicles, passengers

4 Shortest Path Network Shortest path network: (V, E, s, t, c). n Directed graph (V, E). n Source s  V, sink t  V. n Arc costs c(v, w). n Cost of path = sum of arc costs in path. Cost of path s t = = 48. s 3 t

5 Shortest Path Shortest path problem. (CLR ) n Shortest path network (V, E, s, t, c). n Find shortest directed path from s to t. Assumptions. n Network contains directed path from s to every other node. n Network does not contain a negative cost cycle. Application. n Online directions

6 Shortest Path: Existence Existence. If some path from s to v contains a negative cost cycle, there does not exist a shortest path. Otherwise, there exists a shortest s-v that is simple.  If negative cycle, can produce arbitrarily negative path by traversing cycle enough times.  If no negative cycle, can remove cycles without increasing cost. sv C c(C) < 0

7 Shortest Path: Properties Optimal substructure property. All sub-paths of shortest paths are shortest paths. n Let P 1 be x-y sub-path of shortest s-v path P. n Let P 2 be any x-y path. n c(P 1 )  c(P 2 ), otherwise P not shortest s-v path. Triangle inequality. n Let d*(v, w) be the length of the shortest path from v to w. n Then, d*(v, w)  d*(v, x) + d*(x, w) vw x sv P2P2 P1P1 y x

8 Dijkstra's Algorithm Upon termination. n  (v) = distance of shortest s-v path. n pred(v) gives shortest path. for each v  V  (v)   pred(v)  nil  (s)  0 S   init(Q) for each v  V insert(v, Q) while (Q   ) v = delete-min(Q) S  S  {v} for each w s.t (v,w)  E if  (w) >  (v) + c(v,w)  (w)   (v) + c(v,w) pred(w)  v Dijkstra's Algorithm decrease-key

9 Dijkstra's Algorithm: Proof of Correctness Invariant. For each vertex v  S,  (v) = d*(s, v). n Proof by induction on |S|. n Base case: |S| = 0 is trivial. n Induction step: – suppose Dijkstra's algorithm adds vertex v to S –  (v) is the length of the some path from s to v – if  (v) is not the length of the shortest s-v path, then let P* be a shortest s-v path – P* must use an edge that leaves S, say (x, y) – then  (v)> d*(s, v) assumption = d*(s, x) + d(x, y) + d*(y, v)optimal substructure  d*(s, x) + d(x, y) nonnegative lengths =  (x) + d(x, y) inductive hypothesis   (y) algorithm so Dijkstra's algorithm would have selected y instead of v S s y v x P*

10 Dijkstra 1 make-heap n insert n delete-min m decrease-key Priority Queues and Heaps (CLR 20, 21) make-heap Operation insert find-min delete-min union decrease-key delete 1 Binary log N 1 N 1 Binomial log N 1 Fibonacci * 1 1 log N Relaxed 1 1 log N Linked List 1 N N 1 1 N n (n) + m(1) = O(n 2 ) n (log n) + m(log n) = O(m log n) n (log n) + m(1) = O(m + n log n) is-empty11111 Heaps

11 Shortest Path Extensions Variants of shortest path: n Undirected graph. – O(m + n) using Thorup's algorithm n Negative weights but no negative cycles. – O(mn) using Bellman-Ford n Unit weights. – O(m + n) using breadth first search n Integer weights between 0 and constant C. n DAGs. – O(m + n) using topological sort n All-pairs. – O(n 3 ) using Floyd-Warshall – O(mn + n log log n) using Pettie's algorithm

Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Shortest Path: Extra Slides

13 Shortest Path: Proving Optimality How can we verify that a given solution is really optimal? s 3 t

14 Shortest Path: Proving Optimality How can we verify that a given solution is really optimal? n Easy if all weights nonnegative, and there exists a zero cost path. s 3 t