Shortest Path Problems

Slides:



Advertisements
Similar presentations
Single Source Shortest Paths
Advertisements

§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
The Greedy Approach Chapter 8. The Greedy Approach It’s a design technique for solving optimization problems Based on finding optimal local solutions.
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.
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.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Shortest Paths Definitions Single Source Algorithms
Fibonacci Heaps. Single Source All Destinations Shortest Paths
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.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Dijkstra’s Algorithm Supervisor: Dr.Franek Ritu Kamboj
Data Structures & Algorithms Shortest Paths Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Fibonacci Heaps. Analysis FibonacciAnalysis.ppt Video  iew/cop5536sahni
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
1 Ch18. The Greedy Methods. 2 BIRD’S-EYE VIEW Enter the world of algorithm-design methods In the remainder of this book, we study the methods for the.
1 Chapter 6 : Graph – Part 2 교수 : 이상환 강의실 : 113,118 호, 324 호 연구실 : 과학관 204 호 Home :
Shortest Path -Prim’s -Djikstra’s. PRIM’s - Minimum Spanning Tree -A spanning tree of a graph is a tree that has all the vertices of the graph connected.
Shortest Paths.
Lecture ? The Algorithms of Kruskal and Prim
A vertex u is reachable from vertex v iff there is a path from v to u.
CSC317 Shortest path algorithms
Cinda Heeren / Geoffrey Tien
Algorithms and Data Structures Lecture XIII
Introduction to Graphs
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures and may also be used to do an increase key in a min structure (remove.
Shortest Path Problems
Shortest Path Problems
CS330 Discussion 6.
Shortest Path Graph represents highway system Edges have weights
Minimum-Cost Spanning Tree
Single-Source All-Destinations Shortest Paths With Negative Costs
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Shortest Paths.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Minimum-Cost Spanning Tree
CSE 373: Data Structures and Algorithms
Minimum-Cost Spanning Tree
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Dijkstra’s Shortest Path Algorithm Neil Tang 03/25/2008
Shortest Path Problems
Shortest Path Algorithms
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
Lecture 13 Algorithm Analysis
Algorithms and data structures
Lecture 13 Algorithm Analysis
All pairs shortest path problem
Algorithms: Design and Analysis
Single-Source All-Destinations Shortest Paths With Negative Costs
Dijkstra’s Shortest Path Algorithm Neil Tang 3/2/2010
Shortest Paths.
CSE 373 Data Structures and Algorithms
Shortest Path Problems
Graph Algorithms: Shortest Path
Shortest Paths.
CSE 417: Algorithms and Computational Complexity
Chapter 24: Single-Source Shortest-Path
Chapter 9 Graph algorithms
Single-Source All-Destinations Shortest Paths With Negative Costs
Directed Graphs (Part II)
Topological Sorting Minimum Spanning Trees Shortest Path
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

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. The vertex at which the path ends is the destination vertex.

Optimal Substructure If the shortest route from Seattle to Los Angeles passes through Portland and then Sacramento, then the shortest route from Portland to Los Angeles must pass through Sacramento too The problem of how to get from Portland to Los Angeles is nested inside the problem of how to get from Seattle to Los Angeles. Source: https://en.wikipedia.org/wiki/Optimal_substructure

Example A path from 1 to 7. Path length is 14. 8 2 3 1 16 7 6 4 10 4 5

Example Another path from 1 to 7. Path length is 11. 8 2 3 1 16 7 6 4 5 10 4 2 4 7 5 3 14 Another path from 1 to 7. Path length is 11.

Shortest Path Problems Single source single destination. Single source all destinations. All pairs (every vertex is a source and destination).

Single Source Single Destination Possible greedy algorithm: Leave source vertex using cheapest/shortest edge. Leave new vertex using cheapest edge subject to the constraint that a new vertex is reached. Continue until destination is reached.

Greedy Shortest 1 To 7 Path 8 6 2 1 3 3 1 16 7 6 4 5 10 4 2 4 7 5 3 14 Path length is 12. Not shortest path. Algorithm doesn’t work!

Single Source All Destinations Need to generate up to n (n is number of vertices) paths (including path from source to itself). Greedy method: Construct these up to n paths in order of increasing length. Assume edge costs (lengths) are >= 0. So, no path has length < 0. First shortest path is from the source vertex to itself. The length of this path is 0. The solution to the problem consists of up to n paths. The greedy method suggests building these n paths in order of increasing length. First build the shortest of the up to n paths (I.e., the path to the nearest destination). Then build the second shortest path, and so on.

Greedy Single Source All Destinations 8 6 2 1 3 3 1 16 7 6 4 5 10 4 2 4 7 5 3 14 Path Length 1 2 6 1 1 3 9 5 4 1 3 2 1 3 10 6 1 3 5 1 3 11 6 7

Greedy Single Source All Destinations Length Path Each path (other than first) is a one edge extension of a previous path. Next shortest path is the shortest one edge extension of an already generated shortest path. 1 2 1 3 1 3 5 5 1 2 6 1 3 9 5 4 1 3 10 6 1 3 11 6 7

Greedy Single Source All Destinations Let d(i) (distanceFromSource(i)) be the length of a shortest one edge extension of an already generated shortest path, the one edge extension ends at vertex i. The next shortest path is to an as yet unreached vertex for which the d() value is least. Let p(i) (predecessor(i)) be the vertex just before vertex i on the shortest one edge extension to i.

Greedy Single Source All Destinations 8 6 2 1 3 3 3 1 16 7 6 4 5 10 4 2 2 4 4 7 7 5 3 14 1 [1] [2] [3] [4] [5] [6] [7] d p 6 2 2 16 - - 14 - 1 1 1 - - 1

Greedy Single Source All Destinations 8 6 6 2 1 3 3 1 16 7 6 4 5 5 10 4 2 2 4 7 5 3 14 1 1 3 [1] [2] [3] [4] [5] [6] [7] d p 6 2 16 5 5 - 10 - 14 - 1 1 1 3 - 3 - 1

Greedy Single Source All Destinations 8 6 2 1 3 3 1 16 7 6 4 5 10 4 2 4 4 7 7 5 3 14 1 1 3 [1] [2] [3] [4] [5] [6] [7] d p 6 2 9 16 5 - 10 - 14 6 1 3 5 - 1 1 5 1 3 - 3 - 1

Greedy Single Source All Destinations 8 6 2 1 3 3 1 16 7 6 4 5 10 4 2 4 4 7 5 3 14 1 1 3 [1] [2] [3] [4] [5] [6] [7] d p 6 2 9 5 - 10 - 14 9 1 3 5 - 1 1 5 3 - 3 - 1 1 2

Greedy Single Source All Destinations 8 6 2 1 3 3 1 16 7 6 4 5 10 4 2 4 7 7 5 3 14 1 1 3 [1] [2] [3] [4] [5] [6] [7] d p 6 2 9 5 - 10 - 12 14 1 3 5 - 1 1 5 3 - 3 - 4 1 1 2 1 3 5 4

Greedy Single Source All Destinations 8 6 2 1 3 3 1 16 7 6 4 5 10 4 2 4 7 7 5 3 14 1 3 6 [1] [2] [3] [4] [5] [6] [7] d p 6 2 9 5 - 10 - 12 11 14 - 1 1 5 3 - 3 - 4 6 1

Greedy Single Source All Destinations Path 1 3 2 5 6 9 4 10 11 7 Length [1] [2] [3] [4] [5] [6] [7] - 6 1 2 9 5 14 3 10 12 4 11 Can construct shortest paths from the computed p[] data.

Single Source Single Destination Terminate single source all destinations greedy algorithm as soon as shortest path to desired vertex has been generated.

Data Structures For Dijkstra’s Algorithm The greedy single source all destinations algorithm is known as Dijkstra’s algorithm. Implement d() and p() as 1D arrays. Keep a linear list L of reachable vertices to which shortest path is yet to be generated. Select and remove vertex v in L that has smallest d() value. Update d() and p() values of vertices adjacent to v.

Note on Dijkstra’s Directed weighted graph. Does not work with negative cycle In fact, Dijkstra’s prohibits negative edges! Shortest path on a graph with a negative cycle is undefined: Source: http://stackoverflow.com/a/20123207

Complexity O(n) to select next destination vertex. O(out-degree) to update d() and p() values when adjacency lists are used. O(n) to update d() and p() values when adjacency matrix is used. Selection and update done once for each vertex to which a shortest path is found. Total time is O(n2 + e) = O(n2).

Complexity When a min heap of d() values is used in place of the linear list L of reachable vertices, total time is O((n+e) log n), because O(n) remove min operations and O(e) change key (d() value) operations are done. When e is O(n2), using a min heap is worse than using a linear list. When a Fibonacci heap is used, the total time is O(n log n + e). This is asymptotically the fastest known single-source shortest-path algorithm for arbitrary directed graphs with unbounded non-negative weights. * Source *: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm n * remove-min + e * decrease-key, for a min heap nlogn+elogn In a Fibonacci Heap a “decrease-key” operation takes O(1) amortized time