Lecture I: Shortest Path Algorithms
|
|
- Aileen Lee
- 5 years ago
- Views:
Transcription
1 Lecture I: Shortest Path Algorithms Dr Kieran T. Herley Department of Computer Science University College Cork October 201 KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
2 Background Shortest Path Algorithms Setting: directed graph, real edge weights Let the length of a path be the sum of its edge weights and let δ(s, u) = length of shortest path from s to u Reduces to edge distance if all weights are 1 KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
3 Background Example Single source shortest path problem Given a weighted graph G and a designated node s G, determine δ(s, u) for each u G. u δ(s, u) s 0 a 8 b 9 c 7 d 5 All pairs shortest path problem Given a weighted graph G, determine δ(x, y) for each x, y G. KH (21/10/1) Lecture I: Shortest Path Algorithms October 201 / 28
4 Floyd-Warshall Algorithm Graphs and Matrices A Graph and its matrix representation (nodes listed alpahetically a = 1 etc.) if i = j w i,j = weight(i, j) if i j and (i, j) E if i j and (i, j) E No negative cycles allowed otherwise shortest path notion not well defined KH (21/10/1) Lecture I: Shortest Path Algorithms October 201 / 28
5 Floyd-Warshall Algorithm Some Terminology k-path path all of whose intermediate nodes are numbered less than or equal to k; (the start/end nodes may have numbers greater than k). Consider shortest k-path from i to j : Best path is π is better of α or β k γ either it passes through node k (once): 2- i.e. consists of β = shortest (k 1)-path from i to k node k γ = shortest (k 1)-path from k to j or it does not pass through node k: α = shortest (k 1)-path from i to j KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
6 Floyd-Warshall Algorithm A useful identity Definition Claim l (k) i,j = length of shortest k-path joining i to j. l (k) i,j = { wi,j if k = 0 min{l (k 1) i,j, l (k 1) i,k + l (k 1) k,j } if k > 0 KH (21/10/1) Lecture I: Shortest Path Algorithms October 201 / 28
7 Floyd-Warshall Algorithm Observation Visualize the set of l (k) i,j quantities as three-dimensional grid with point l (k) i,j having co-ordinates (i, j, k). l (k) i,j = { wi,j if k = 0 min{l (k 1) i,j, l (k 1) i,k + l (k 1) k,j } if k > 0 Notice: each horizontal slice represents values l (k) i,j for some fixed k the quantities in the bottom slice (k = 0) depend only on edge weights KH (21/10/1) each quantity l (k) Lecture on slice I: Shortest k depends Path Algorithms only on quantities October on the201 slice 7 / 28
8 Floyd-Warshall Algorithm Floyd-Warshall Algorithm Algorithm FLOYD WARSHALL(G): W = matrix of edge weights for i 1 to n do for j 1 to n do L[ i, j, 0] W[i, j ] for k 1 to n do for i 1 to n do for j 1 to n do if L[ i, j, k 1] < L[i, k, k 1] + L[k, j, k 1] L[ i, j, k] L[i, j, k 1] else L[ i, j, k] L[i, k, k 1] + L[k, j, k 1] KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
9 Floyd-Warshall Algorithm Notes Length of shortest i-to-j path in L[i, j, n]. Negative weight OK, but not negative cycles. Running time: O(n ) Can get by with 2D arrays (two for alternate slices) Can be modified to produce paths (not just lengths) KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
10 Floyd-Warshall Algorithm Transitive Closure The transitive closure of G = (V, E) the the graph G = (v, E ) such that there is an edge in G from u ti v if and only if there is a path in G from u to v. Algorithm: Give weight 1 to each edge in G; Run Floyd-Warshall algorithm; Each L[i, j, n] denotes path in G, so add corresponding edge (i, j) to E. KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
11 Single-Source Shortest Path Problem Single source shortest path problem: Given a weighted graph G and a designated node s G, determine δ(s, u) for each u G. Disallow negative edges Could use Floyd-Warshall, but is there a more efficient way? KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
12 Single-source shortest path problem (SSSP) s Problem t y 7 9 x z Path sequence of edge-connected vertices Path length sum of edge lengths Shortest path path between endpoints with minimum total length (SSSP) Given graph G and source vertex s, calculate length of shortest path from source s to each vertex in G. KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
13 Dijkstra s Algorithm s t x s 0 t x 8 Inputs (left): y z G: graph with nonnegative (important!) edges s: start node Outputs (right): Compute for each node v, δ(s, v) = length shortest path from s to v ( if none). Shown inside nodes. y 7 z KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
14 Idea Begin with a crude estimate d[u] for δ(s, u): { 0 if u = s d[u] = otherwise Refine estimates using (carefully chosen) sequence of the following edge operations (i.e. (u, v) must be an edge): Algorithm Relax(u, v): if d[v] > d[u] + weight(u, v) then d[v] d[u] + weight(u, v) Ultimately (we hope) d[u] = δ(s, u), for all u. KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
15 Notes Observation Through any sequence of Relax(u, v) steps d[x] is non-increasing, and If d[x], then there is a path of length d[x] in G from s to x. Algorithm Relax(u, v): if d[v] > d[u] + weight(u, v) then d[v] d[u] + weight(u, v) KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
16 Dijkstra s Algorithm Algorithm Relax(u, v): if d[v] > d[u] + weight(u, v) then d[v] d[u] + weight(u, v) Algorithm Dijkstra(G, s ): Initialize d(s) to 0 Initialize d(x) = INFTY for all x s Create priority queue Q and place each node x in Q with key value d(x) while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
17 Priority queue refresher What Container abstraction holding key, value pairs Operations insert Add new key value item to container min Return the value with the smallest key (ties broken arb.) remove min Return and remove the value with the smallest key Implementation Heap-ordered tree stored in array; insert, remove min O(log n) time. KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
18 D s algorithm in action s 0 t x Q vertex non-q vertex Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) y z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
19 D s algorithm in action s 0 t x Q vertex non-q vertex Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) y z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
20 D s algorithm in action s 0 t x Q vertex non-q vertex Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) y z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
21 D s algorithm in action s 0 1 t x Q vertex non-q vertex y z u vertex Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
22 D s algorithm in action s 0 t x Q vertex non-q vertex Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) y z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
23 D s algorithm in action s 0 t x Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
24 D s algorithm in action s 0 1 t x Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
25 D s algorithm in action s 0 t x Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
26 D s algorithm in action s 0 t x 1 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
27 D s algorithm in action s 0 t x 1 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
28 D s algorithm in action s 0 t x 1 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
29 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
30 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
31 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
32 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
33 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
34 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
35 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
36 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
37 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
38 D s algorithm in action s 0 t x 8 Q vertex non-q vertex y Algorithm Dijkstra(G, s ):... while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) 7 z u vertex KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
39 Aside Relax involves changes to d[] i.e. priority queue keys. New priority queue operation: reduce key(x, k) Replace key of item x with smaller key k Implementation note: Effectively helper method heap decrease key used in insert operation Running time: O(log(queue size)) KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
40 Running time of D s algorithm Algorithm Relax(u, v): if d[v] > d[u] + weight(u, v) then d[v] d[u] + weight(u, v) Algorithm Dijkstra(G, s ): / Initialization stuff / while Q is not empty do u Q.remove min element() for each v in G.neighbours(u) do Relax(u, v) n, m = num. nodes, edges Priority queue operations: O((n + m) log n) (over) Non-priority queue stuff: O(n + m) Total running time: O((n + m) log n) KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
41 Notes Priority queue operations op no. cost per subtotal insert n O(log n) O(n log n) isempty n O(1) O(n) remove min element n O(log n) O(n log n) replacekey m O(log n) O(m log n) Non-priority queue stuff n iterations in all for fixed u, for-loop takes O(#edges leaving u) time Total O(n) + O(#edges leaving u) = O(n + m) }{{} u V while } {{ } for O((n + m) log n) + O(n + m) = O((n + m) log n) KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
42 Claim 1 Definition We say x is settled once d(x) = δ(s, x). Claim If u is settled and s u v is a shortest path to v, then following Relax(u, v) v is also settled KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
43 Claim 1 Definition We say x is settled once d(x) = δ(s, x). Claim If u is settled and s u v is a shortest path to v, then following Relax(u, v) v is also settled Before: Relax(u, v), d(u) = δ(s, u) After: Relax(u, v), d(v) d(u) + w(u, v) KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
44 Claim 1 Definition We say x is settled once d(x) = δ(s, x). Claim If u is settled and s u v is a shortest path to v, then following Relax(u, v) v is also settled Before: Relax(u, v), d(u) = δ(s, u) After: Relax(u, v), d(v) d(u) + w(u, v) This must equal δ(s, v): shortest path assumption KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
45 Claim 2 Claim Node u is settled before being removed from Q. Proof. Suppose this were not true Let u be the first node removed from Q that was not settled Let y be first node along shortest path from s to u that is in Q and x be its predecessor KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
46 Claim 2 cont d Claim Node u is settled before being removed from Q. d(u) d(y) by EXTRACTMINs choice of u = δ(s, y) x not in Q so d(x) = δ(s, x); Relax(x, y) operation ensures that d(y) = δ(s, y) δ(s, u) since s-to-y a prefix of s-to-u and edge-weights are non-negative d(u) KH (21/10/1) Lecture I: Shortest Path Algorithms Hence d(u) = δ(s, October u) / 28
47 Constructing the Paths Minor tweak to Relax to record shortest-path predecessors so algorithms constructs paths not just their length. Algorithm Relax(u, v): if d[v] > d[u] + weight(u, v) then d[v] d[u] + weight(u, v) p[v] u At conclusion, p(x) indicates parent of x in a (shortest-path) tree rooted at s. The root to leaf path to x is a shortest path. KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
48 SP Algorithms and Network Routing network of hosts/switches(nodes) and links (edges) edge weight desirability of using edge Determine for/at each node, the lowest cost route to each destination Would like approach to be distributed resilient to failures/changes KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
49 Idea 1 Each node determines its neighbours/edges and costs and injects into into network. (Re-injects following changes) Nodes exchange this information among themselves Each node gets complete map of the network Changes get reflected in maps as new info replaces old KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
50 Idea 2 Each node x runs Dijkstra locally to establish best paths from x to other network nodes Maintains table of (dest., cost, next-hop) entries for routing decisions Information re-computed when network map changes KH (21/10/1) Lecture I: Shortest Path Algorithms October / 28
Lecture 11: Analysis of Algorithms (CS ) 1
Lecture 11: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 12, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 2 Dynamic Programming Approach Floyd-Warshall Shortest
More informationSingle Source Shortest Path (SSSP) Problem
Single Source Shortest Path (SSSP) Problem Single Source Shortest Path Problem Input: A directed graph G = (V, E); an edge weight function w : E R, and a start vertex s V. Find: for each vertex u V, δ(s,
More informationfrom notes written mostly by Dr. Carla Savage: All Rights Reserved
CSC 505, Fall 2000: Week 9 Objectives: learn about various issues related to finding shortest paths in graphs learn algorithms for the single-source shortest-path problem observe the relationship among
More informationShortest Path Problem
Shortest Path Problem CLRS Chapters 24.1 3, 24.5, 25.2 Shortest path problem Shortest path problem (and variants) Properties of shortest paths Algorithmic framework Bellman-Ford algorithm Shortest paths
More informationSingle Source Shortest Path
Single Source Shortest Path A directed graph G = (V, E) and a pair of nodes s, d is given. The edges have a real-valued weight W i. This time we are looking for the weight and the shortest path from s
More informationMinimum Spanning Trees
Minimum Spanning Trees Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and no
More informationShortest Path Algorithms. Lecture I: Shortest Path Algorithms. Example. Graphs and Matrices. Setting: Dr Kieran T. Herley.
Shores Pah Algorihms Background Seing: Lecure I: Shores Pah Algorihms Dr Kieran T. Herle Deparmen of Compuer Science Universi College Cork Ocober 201 direced graph, real edge weighs Le he lengh of a pah
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 07 Single-Source Shortest Paths (Chapter 24) Stephen Scott and Vinodchandran N. Variyam sscott@cse.unl.edu 1/36 Introduction
More informationShortest path problems
Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths
More informationArtificial Intelligence
Artificial Intelligence Shortest Path Problem G. Guérard Department of Nouvelles Energies Ecole Supérieur d Ingénieurs Léonard de Vinci Lecture 3 GG A.I. 1/42 Outline 1 The Shortest Path Problem Introduction
More informationGraphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College
Laura Toma Algorithms (csci2200), Bowdoin College Topics Weighted graphs each edge (u, v) has a weight denoted w(u, v) or w uv stored in the adjacency list or adjacency matrix The weight of a path p =
More informationDijkstra s Shortest Path Algorithm
Dijkstra s Shortest Path Algorithm DPV 4.4, CLRS 24.3 Revised, October 23, 2014 Outline of this Lecture Recalling the BFS solution of the shortest path problem for unweighted (di)graphs. The shortest path
More informationIntroduction Single-source shortest paths All-pairs shortest paths. Shortest paths in graphs
Shortest paths in graphs Remarks from previous lectures: Path length in unweighted graph equals to edge count on the path Oriented distance (δ(u, v)) between vertices u, v equals to the length of the shortest
More informationMinimum Spanning Trees. Lecture II: Minimium Spanning Tree Algorithms. An Idea. Some Terminology. Dr Kieran T. Herley
Lecture II: Minimium Spanning Tree Algorithms Dr Kieran T. Herley Department of Computer Science University College Cork April 016 Spanning Tree tree formed from graph edges that touches every node (e.g.
More informationCS4800: Algorithms & Data Jonathan Ullman
CS4800: Algorithms & Data Jonathan Ullman Lecture 13: Shortest Paths: Dijkstra s Algorithm, Heaps DFS(?) Feb 0, 018 Navigation s 9 15 14 5 6 3 18 30 11 5 0 16 4 6 6 3 19 t Weighted Graphs A graph with
More informationAlgorithms for Data Science
Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Shortest paths in weighted graphs (Bellman-Ford, Floyd-Warshall) Outline 1 Shortest paths in graphs with
More informationWeek 12: Minimum Spanning trees and Shortest Paths
Agenda: Week 12: Minimum Spanning trees and Shortest Paths Kruskal s Algorithm Single-source shortest paths Dijkstra s algorithm for non-negatively weighted case Reading: Textbook : 61-7, 80-87, 9-601
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 6 Greedy Graph Algorithms Shortest paths Adam Smith 9/8/14 The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle Does
More informationTheory of Computing. Lecture 7 MAS 714 Hartmut Klauck
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck Shortest paths in weighted graphs We are given a graph G (adjacency list with weights W(u,v)) No edge means W(u,v)=1 We look for shortest paths from
More information1 Dijkstra s Algorithm
Lecture 11 Dijkstra s Algorithm Scribes: Himanshu Bhandoh (2015), Virginia Williams, and Date: November 1, 2017 Anthony Kim (2016), G. Valiant (2017), M. Wootters (2017) (Adapted from Virginia Williams
More informationChapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems
Chapter 24. Shortest path problems We are given a directed graph G = (V,E) with each directed edge (u,v) E having a weight, also called a length, w(u,v) that may or may not be negative. A shortest path
More informationIntroduction. I Given a weighted, directed graph G =(V, E) with weight function
ntroduction Computer Science & Engineering 2/82 Design and Analysis of Algorithms Lecture 06 Single-Source Shortest Paths (Chapter 2) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu
More informationSingle Source Shortest Paths
Single Source Shortest Paths Given a connected weighted directed graph G(V, E), associated with each edge u, v E, there is a weight w(u, v). The single source shortest paths (SSSP) problem is to find a
More informationCS2210 Data Structures and Algorithms
S1 ata Structures and Algorithms Lecture 1 : Shortest Paths A 4 1 5 5 3 4 Goodrich, Tamassia Outline Weighted Graphs Shortest Paths Algorithm (ijkstra s) Weighted Graphs ach edge has an associated numerical
More informationChapter 25: All-Pairs Shortest-Paths
Chapter : All-Pairs Shortest-Paths When no negative edges Some Algorithms Using Dijkstra s algorithm: O(V ) Using Binary heap implementation: O(VE lg V) Using Fibonacci heap: O(VE + V log V) When no negative
More informationLecture 17: Weighted Graphs, Dijkstra s Algorithm. Courtesy of Goodrich, Tamassia and Olga Veksler
Lecture 17: Weighted Graphs, Shortest Paths: Dijkstra s Algorithm A 4 B 7 C 1 D 3 5 3 9 5 E Courtesy of Goodrich, Tamassia and Olga Veksler Instructor: Yuzhen Xie Weighted Graphs In a weighted graph, each
More informationObject-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018
Object-oriented programming and data-structures CS/ENGRD 20 SUMMER 208 Lecture 3: Shortest Path http://courses.cs.cornell.edu/cs20/208su Graph Algorithms Search Depth-first search Breadth-first search
More informationAnalysis of Algorithms, I
Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, March 8, 2016 Outline 1 Recap Single-source shortest paths in graphs with real edge weights:
More informationAlgorithms on Graphs: Part III. Shortest Path Problems. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..
.. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar.. Shortest Path Problems Algorithms on Graphs: Part III Path in a graph. Let G = V,E be a graph. A path p = e 1,...,e k, e i E,
More informationShortest Paths. Nishant Mehta Lectures 10 and 11
Shortest Paths Nishant Mehta Lectures 0 and Communication Speeds in a Computer Network Find fastest way to route a data packet between two computers 6 Kbps 4 0 Mbps 6 6 Kbps 6 Kbps Gbps 00 Mbps 8 6 Kbps
More informationModule 5 Graph Algorithms
Module 5 Graph lgorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 97 E-mail: natarajan.meghanathan@jsums.edu 5. Graph Traversal lgorithms Depth First
More informationAll Pairs Shortest Paths
All Pairs Shortest Paths Given a directed, connected weighted graph G(V, E), for each edge u, v E, a weight w(u, v) is associated with the edge. The all pairs of shortest paths problem (APSP) is to find
More informationOutline. Computer Science 331. Definitions: Paths and Their Costs. Computation of Minimum Cost Paths
Outline Computer Science 33 Computation of Minimum-Cost Paths Dijkstra s Mike Jacobson Department of Computer Science University of Calgary Lecture #34 Dijkstra s to Find Min-Cost Paths 3 Example 4 5 References
More informationIntroduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15
600.363 Introduction to Algorithms / 600.463 Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15 14.1 Introduction Today we re going to talk about algorithms for computing shortest
More informationShortest Paths. Nishant Mehta Lectures 10 and 11
Shortest Paths Nishant Mehta Lectures 0 and Finding the Fastest Way to Travel between Two Intersections in Vancouver Granville St and W Hastings St Homer St and W Hastings St 6 Granville St and W Pender
More informationAlgorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University
Algorithms All-Pairs Shortest Paths Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr Contents Using single source shortest path algorithms Presents O(V 4 )-time algorithm, O(V 3 log V)-time algorithm,
More information1 The Shortest Path Problem
CS161 Lecture 11 Single Source Shortest Paths Scribed by: Romil Verma (2015), Virginia Date: May 8, 2016 1 The Shortest Path Problem In this lecture, we ll discuss the shortest path problem. Assume we
More informationCOL 702 : Assignment 1 solutions
COL 70 : Assignment 1 solutions 1(a ( n T (n = T + bn log n ( n = T + b n ( n log + bn log n ( n = T + b n ( n 8 log + b n log ( n + bn log n = bn log n + b n log n + bn log n +... log n terms = nb [(log
More informationAlgorithms for Data Science
Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Thursday, October 1, 2015 Outline 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra
More informationCHAPTER 13 GRAPH ALGORITHMS
CHAPTER 13 GRAPH ALGORITHMS SFO LAX ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 00) AND SLIDES FROM NANCY
More informationTaking Stock. IE170: Algorithms in Systems Engineering: Lecture 20. Example. Shortest Paths Definitions
Taking Stock IE170: Algorithms in Systems Engineering: Lecture 20 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 19, 2007 Last Time Minimum Spanning Trees Strongly
More informationDirected Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1
Directed Graphs Definitions. Representations. ADT s. Single Source Shortest Path Problem (Dijkstra, Bellman-Ford, Floyd-Warshall). Traversals for DGs. Parenthesis Lemma. DAGs. Strong Components. Topological
More informationParallel Graph Algorithms
Parallel Graph Algorithms Design and Analysis of Parallel Algorithms 5DV050/VT3 Part I Introduction Overview Graphs definitions & representations Minimal Spanning Tree (MST) Prim s algorithm Single Source
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationLecture #10: RELAX(u, v, w) if d[v] >d[u]+w(u, v) then d[v] d[u]+w(u, v) π[v] u
Lecture #:.. raph lgorithms: hortest Path (hapter ) Problem iven a directed graph =[V,], and weight function w : R mapping edges to real valued weights. The weight of a path p = hv o,v,..., v k i is the
More informationLecture 18 Solving Shortest Path Problem: Dijkstra s Algorithm. October 23, 2009
Solving Shortest Path Problem: Dijkstra s Algorithm October 23, 2009 Outline Lecture 18 Focus on Dijkstra s Algorithm Importance: Where it has been used? Algorithm s general description Algorithm steps
More informationDijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the
Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the Floyd-Warshall algorithm in O(n 3 ) time. Neither of
More informationIntroduction. I Given a weighted, directed graph G =(V, E) with weight function
ntroduction Computer Science & Engineering 2/82 Design and Analysis of Algorithms Lecture 05 Single-Source Shortest Paths (Chapter 2) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu
More informationBreadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2
Breadth-First Search, Slides for CIS DPV Chapter Jim Royer EECS October, 00 Definition In an undirected graph, the distance between two vertices is the length of the shortest path between them. (If there
More informationDijkstra s Algorithm. Dijkstra s algorithm is a natural, greedy approach towards
CPSC-320: Intermediate Algorithm Design and Analysis 128 CPSC-320: Intermediate Algorithm Design and Analysis 129 Dijkstra s Algorithm Dijkstra s algorithm is a natural, greedy approach towards solving
More informationOutline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4.
Weighted Graphs 1 Outline (single-source) shortest path Dijkstra (Section 4.4) Bellman-Ford (Section 4.6) (all-pairs) shortest path Floyd-Warshall (Section 6.6) minimum spanning tree Kruskal (Section 5.1.3)
More informationDesign and Analysis of Algorithms 演算法設計與分析. Lecture 13 December 18, 2013 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 13 December 18, 2013 洪國寶 1 Homework #10 1. 24.1-1 (p. 591 / p. 654) 2. 24.1-6 (p. 592 / p. 655) 3. 24.3-2 (p. 600 / p. 663) 4. 24.3-8 (p. 601) / 24.3-10
More informationDescription of The Algorithm
Description of The Algorithm Dijkstra s algorithm works by solving the sub-problem k, which computes the shortest path from the source to vertices among the k closest vertices to the source. For the dijkstra
More informationAdvanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2007 Simonas Šaltenis
Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2007 Simonas Šaltenis 3.2.12 simas@cs.aau.dk All-pairs shortest paths Main goals of the lecture: to go through one more example of dynamic programming
More informationCSE 502 Class 23. Jeremy Buhler Steve Cole. April BFS solves unweighted shortest path problem. Every edge traversed adds one to path length
CSE 502 Class 23 Jeremy Buhler Steve Cole April 14 2015 1 Weighted Version of Shortest Paths BFS solves unweighted shortest path problem Every edge traversed adds one to path length What if edges have
More informationCS420/520 Algorithm Analysis Spring 2009 Lecture 14
CS420/520 Algorithm Analysis Spring 2009 Lecture 14 "A Computational Analysis of Alternative Algorithms for Labeling Techniques for Finding Shortest Path Trees", Dial, Glover, Karney, and Klingman, Networks
More informationLecture 5: Graph algorithms 1
DD2458, Problem Solving and Programming Under Pressure Lecture 5: Graph algorithms 1 Date: 2008-10-01 Scribe(s): Mikael Auno and Magnus Andermo Lecturer: Douglas Wikström This lecture presents some common
More informationDynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs).
Lecture 13 Graph Algorithms I 13.1 Overview This is the first of several lectures on graph algorithms. We will see how simple algorithms like depth-first-search can be used in clever ways (for a problem
More informationIntroduction to Algorithms. Lecture 11
Introduction to Algorithms Lecture 11 Last Time Optimization Problems Greedy Algorithms Graph Representation & Algorithms Minimum Spanning Tree Prim s Algorithm Kruskal s Algorithm 2 Today s Topics Shortest
More informationDijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker
Dijkstra s Single Source Shortest Path Algorithm Andreas Klappenecker Single Source Shortest Path Given: a directed or undirected graph G = (V,E) a source node s in V a weight function w: E -> R. Problem:!!
More informationThe Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation
The Shortest Path Problem jla,jc@imm.dtu.dk Department of Management Engineering Technical University of Denmark The Shortest Path Problem Given a directed network G = (V,E,w) for which the underlying
More informationSingle Source Shortest Path: The Bellman-Ford Algorithm. Slides based on Kevin Wayne / Pearson-Addison Wesley
Single Source Shortest Path: The Bellman-Ford Algorithm Slides based on Kevin Wayne / Pearson-Addison Wesley Single Source Shortest Path Problem Shortest path network. Directed graph G = (V, E, w). Weight
More informationShortest Paths D E. Shortest Paths 1
Shortest Paths A 2 7 2 B C D 2 E F Shortest Paths Outline and Reading Weighted graphs ( 7.) Shortest path problem Shortest path properties Dijkstra s algorithm ( 7..) Algorithm Edge relaxation The Bellman-Ford
More informationTIE Graph algorithms
TIE-20106 1 1 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common
More informationParallel Graph Algorithms
Parallel Graph Algorithms Design and Analysis of Parallel Algorithms 5DV050 Spring 202 Part I Introduction Overview Graphsdenitions, properties, representation Minimal spanning tree Prim's algorithm Shortest
More informationCS350: Data Structures Dijkstra s Shortest Path Alg.
Dijkstra s Shortest Path Alg. James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Shortest Path Algorithms Several different shortest path algorithms exist
More informationCOT 6405 Introduction to Theory of Algorithms
COT 6405 Introduction to Theory of Algorithms Topic 16. Single source shortest path 11/18/2015 1 Problem definition Problem: given a weighted directed graph G, find the minimum-weight path from a given
More informationDijkstra s Algorithm
Dijkstra s Algorithm 7 1 3 1 Weighted Graphs In a weighted graph, each edge has an associated numerical value, called the weight of the edge Edge weights may represent, distances, costs, etc. Example:
More informationTitle. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.
Title Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis Nesrine Damak Fakultät für Informatik TU München 20. September 2010 Nesrine Damak: Classical Shortest-Path Algorithms 1/ 35
More informationCOMP251: Single source shortest paths
COMP51: Single source shortest paths Jérôme Waldispühl School of Computer Science McGill University Based on (Cormen et al., 00) Problem What is the shortest road to go from one city to another? Eample:
More information5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456
5.4 Shortest Paths CH08-320201: Algorithms and Data Structures 456 Definitions: Path Consider a directed graph G=(V,E), where each edge e є E is assigned a non-negative weight w: E -> R +. A path is a
More informationGraph Algorithms shortest paths, minimum spanning trees, etc.
Graph Algorithms shortest paths, minimum spanning trees, etc. SFO ORD LAX DFW Graphs 1 Outline and Reading Graphs ( 1.1) Definition Applications Terminology Properties ADT Data structures for graphs (
More informationThe Shortest Path Problem
The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring
More informationMA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati
MA 252: Data Structures and Algorithms Lecture 36 http://www.iitg.ernet.in/psm/indexing_ma252/y12/index.html Partha Sarathi Mandal Dept. of Mathematics, IIT Guwahati The All-Pairs Shortest Paths Problem
More informationTaking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution
Taking Stock IE170: Algorithms in Systems Engineering: Lecture 26 Jeff Linderoth Last Time Department of Industrial and Systems Engineering Lehigh University April 2, 2007 This Time Review! Jeff Linderoth
More informationWeighted Graph Algorithms Presented by Jason Yuan
Weighted Graph Algorithms Presented by Jason Yuan Slides: Zachary Friggstad Programming Club Meeting Weighted Graphs struct Edge { int u, v ; int w e i g h t ; // can be a double } ; Edge ( int uu = 0,
More informationMore Graph Algorithms: Topological Sort and Shortest Distance
More Graph Algorithms: Topological Sort and Shortest Distance Topological Sort The goal of a topological sort is given a list of items with dependencies, (ie. item 5 must be completed before item 3, etc.)
More informationLecture 6 Basic Graph Algorithms
CS 491 CAP Intro to Competitive Algorithmic Programming Lecture 6 Basic Graph Algorithms Uttam Thakore University of Illinois at Urbana-Champaign September 30, 2015 Updates ICPC Regionals teams will be
More informationtree follows. Game Trees
CPSC-320: Intermediate Algorithm Design and Analysis 113 On a graph that is simply a linear list, or a graph consisting of a root node v that is connected to all other nodes, but such that no other edges
More information4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24
/8/11 Single-Source Shortest Path Chapter 1 Shortest Paths Finding the shortest path between two nodes comes up in many applications o Transportation problems o Motion planning o Communication problems
More information1 Non greedy algorithms (which we should have covered
1 Non greedy algorithms (which we should have covered earlier) 1.1 Floyd Warshall algorithm This algorithm solves the all-pairs shortest paths problem, which is a problem where we want to find the shortest
More informationRouting Protocols and the IP Layer
Routing Protocols and the IP Layer CS244A Review Session 2/0/08 Ben Nham Derived from slides by: Paul Tarjan Martin Casado Ari Greenberg Functions of a router Forwarding Determine the correct egress port
More informationCSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li
CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast
More informationClassical Shortest-Path Algorithms
DISTANCE PROBLEMS IN NETWORKS - THEORY AND PRACTICE Classical Shortest-Path Algorithms Nesrine Damak October 10, 2010 Abstract In this work, we present four algorithms for the shortest path problem. The
More informationUnit 2: Algorithmic Graph Theory
Unit 2: Algorithmic Graph Theory Course contents: Introduction to graph theory Basic graph algorithms Reading Chapter 3 Reference: Cormen, Leiserson, and Rivest, Introduction to Algorithms, 2 nd Ed., McGraw
More informationAlgorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1
Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm ADS: lects 14 & 15 slide 1 Weighted Graphs Definition 1 A weighted (directed or undirected graph) is a pair (G, W ) consisting
More informationCS521 \ Notes for the Final Exam
CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )
More informationCSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo
CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve
More informationTutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].
Tutorial Question 1 A depth-first forest classifies the edges of a graph into tree, back, forward, and cross edges. A breadth-first tree can also be used to classify the edges reachable from the source
More informationLecture 4: Graph Algorithms
Lecture 4: Graph Algorithms Definitions Undirected graph: G =(V, E) V finite set of vertices, E finite set of edges any edge e = (u,v) is an unordered pair Directed graph: edges are ordered pairs If e
More informationShortest Paths. CSE 373 Data Structures Lecture 21
Shortest Paths CSE 7 Data Structures Lecture Readings and References Reading Section 9., Section 0.. Some slides based on: CSE 6 by S. Wolfman, 000 //0 Shortest Paths - Lecture Path A path is a list of
More informationCS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review
1 Review 1 Something I did not emphasize enough last time is that during the execution of depth-firstsearch, we construct depth-first-search trees. One graph may have multiple depth-firstsearch trees,
More informationShortest Paths. Shortest Path. Applications. CSE 680 Prof. Roger Crawfis. Given a weighted directed graph, one common problem is finding the shortest
Shortest Path Introduction to Algorithms Shortest Paths CS 60 Prof. Roger Crawfis Given a weighted directed graph, one common problem is finding the shortest path between two given vertices Recall that
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 7 Greedy Graph Algorithms Topological sort Shortest paths Adam Smith The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle
More informationSHORTEST PATHS. Weighted Digraphs. Shortest paths. Shortest Paths BOS ORD JFK SFO LAX DFW MIA
SHORTEST PATHS Weighted Digraphs Shortest paths 6 867 1 Weighted Graphs weights on the edges of a graph represent distances, costs, etc. An example of an undirected weighted graph: 6 867 2 Shortest Path
More informationCS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14
CS200: Graphs Rosen Ch. 9.1-9.4, 9.6, 10.4-10.5 Walls and Mirrors Ch. 14 Trees as Graphs Tree: an undirected connected graph that has no cycles. A B C D E F G H I J K L M N O P Rooted Trees A rooted tree
More informationGraph Algorithms shortest paths, minimum spanning trees, etc.
SFO ORD LAX Graph Algorithms shortest paths, minimum spanning trees, etc. DFW Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with
More informationGraphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College
Laura Toma Algorithms (csci2200), Bowdoin College Undirected graphs Concepts: connectivity, connected components paths (undirected) cycles Basic problems, given undirected graph G: is G connected how many
More informationMinimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem
Minimum Spanning Trees (Forests) Given an undirected graph G=(V,E) with each edge e having a weight w(e) : Find a subgraph T of G of minimum total weight s.t. every pair of vertices connected in G are
More informationCSE 421 Greedy Alg: Union Find/Dijkstra s Alg
CSE 1 Greedy Alg: Union Find/Dijkstra s Alg Shayan Oveis Gharan 1 Dijkstra s Algorithm Dijkstra(G, c, s) { d s 0 foreach (v V) d[v] //This is the key of node v foreach (v V) insert v onto a priority queue
More information