Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4.

Size: px
Start display at page:

Download "Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4."

Transcription

1 Weighted Graphs 1

2 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) Prim (Section 5.1.5)

3 Shortest Path Problems How can we find the shortest route between two points on a road map? Model the problem as a graph problem: Road map is a weighted graph: vertices = cities edges = road segments between cities edge weights = road distances Goal: find a shortest path between two vertices (cities) 3

4 Shortest Path Problem Input: Directed graph G = (V, E) Weight function w : E R Weight of path p = v 0, v 1,..., v k w( p) k i 1 w( v i 1, v i ) Shortest-path weight from u to v: s 0 t y x z 7 δ(u, v) = min w(p) : u p v if there exists a path from u to v otherwise Note: there might be multiple shortest paths from u to v 4

5 Variants of Shortest Path Single-source shortest paths G = (V, E) find a shortest path from a given source vertex s to each vertex v V Single-destination shortest paths Find a shortest path to a given destination vertex t from each vertex v Question: How to solve it? 5

6 Variants of Shortest Path Single-source shortest paths G = (V, E) find a shortest path from a given source vertex s to each vertex v V Single-destination shortest paths Find a shortest path to a given destination vertex t from each vertex v Reversing the direction of each edge single-source 6

7 Variants of Shortest Paths (cont d) Single-pair shortest path Find a shortest path from u to v for given vertices u and v All-pairs shortest-paths Find a shortest path from u to v for every pair of vertices u and v 7

8 Shortest-Path Problems Single-source (single-destination). Find a shortest path from a given source (vertex s) to all the other vertices positive weights greedy algorithm pos. & neg. weights dynamic programming All-pairs. Find shortest-paths for every pair of vertices pos. & neg. weights dynamic programming 8

9 Optimal Substructure Theorem Given: v j A weighted, directed graph G = (V, E) v 1 p jk A weight function w: E R, p 1i p ij p ij v k A shortest path p = v 1, v,..., v k from v 1 to v k v i A subpath of p: p ij = v i, v i+1,..., v j, with 1 i j k Then: p ij is a shortest path from v i to v j p 1i p ij p jk Proof: p = v 1 v i v j v k w(p) = w(p 1i ) + w(p ij ) + w(p jk ) Assume p ij from v i to v j with w(p ij ) < w(p ij ) w(p ) = w(p 1i ) + w(p ij ) + w(p jk ) < w(p) contradiction! 9

10 Triangle Inequality for positive weights s For all (u, v) E, we have: δ (s, v) δ (s, u) + δ (u, v) u v - If u is on the shortest path to v we have the equality sign s u v 10

11 Algorithms Operations common in both algorithms: Initialization Relaxation Dijkstra s algorithm Negative weights are not allowed Bellman-Ford algorithm Negative weights are allowed Negative cycles reachable from the source are not allowed. 11

12 Shortest-Paths Notation For each vertex v V: δ(s, v): shortest-path weight d[v]: shortest-path weight estimate Initially, d[v]= d[v] δ(s,v) as algorithm progresses [v] = predecessor of v on a shortest path from s If no predecessor, [v] = NIL induces a tree shortest-path tree s 0 t y x z 7 1

13 Initialization Alg.: INITIALIZE-SINGLE-SOURCE(V, s) 1. for each v V. do d[v] 3. [v] NIL 4. d[s] 0 All the shortest-paths algorithms start with INITIALIZE-SINGLE-SOURCE 13

14 Relaxation Step Relaxing an edge (u, v) = testing whether we can improve the shortest path to v found so far by going through u If d[v] > d[u] + w(u, v) we can improve the shortest path to v s u d[v]=d[u]+w(u,v) [v] u v 5 9 s u v 5 6 After relaxation: d[v] d[u] + w(u, v) RELAX(u, v, w) RELAX(u, v, w) u v 5 7 u v 5 6 no change 14

15 Dijkstra s algorithm 15

16 Dijkstra s Algorithm Single-source shortest path problem: positive-weight edges: w(u, v) > 0, (u, v) E Each edge is relaxed only once! Maintains two sets of vertices: d[v]=δ (s, v) d[v]>δ (s, v) 16

17 Dijkstra s Algorithm (cont.) Vertices in V S reside in a min-priority queue Keys in Q are estimates of shortest-path weights d[u] Repeatedly select a vertex u V S, with the minimum shortest-path estimate d[u] Relax all edges leaving u 17

18 Dijkstra (G, w, s) s 0 S=<> Q=<s,t,x,z,y> S=<s> Q=<y,t,x,z> 10 t 3 5 y x z s 0 10 t y x z 18

19 Example (cont.) 10 t x 10 t x s s y 7 z y 7 z S=<s,y> Q=<z,t,x> S=<s,y,z> Q=<t,x> 19

20 Example (cont.) S=<s,y,z,t> Q=<x> S=<s,y,z,t,x> Q=<> s t y 9 x z s t y 9 x z 0

21 Dijkstra (G, w, s) 1. INITIALIZE-SINGLE-SOURCE(V, s). S 3. Q V[G] 4. while Q 5. do u EXTRACT-MIN(Q) 6. S S {u} O(V) build min-heap 7. for each vertex v Adj[u] 8. do RELAX(u, v, w) Executed O(V) times O(lgV) 9. Update Q (DECREASE_KEY) (V) O(VlgV) O(E) times (total) O(lgV) O(ElgV) Running time: O(VlgV + ElgV) = O(ElgV) 1

22 Binary Heap vs Fibonacci Heap Running time depends on the implementation of the heap

23 Correctness Dijkstra s algorithm is a greedy algorithm make choices that currently seem the best locally optimal does not always mean globally optimal Correct because maintains following two properties: for every known vertex, recorded distance is shortest distance to that vertex from source vertex for every unknown vertex v, its recorded distance is shortest path distance to v from source vertex, considering only currently known vertices and v Let s prove the Correctness 3

24 Correctness of Dijskstra s Algorithm For each vertex u V, we have d[u] = δ(s, u) at the time when u is added to S. Proof: Let u be the first vertex for which d[u] δ(s, u) when added to S Let s look at a true shortest path p from s to u: 4

25 Correctness of Dijskstra s Algorithm What is the value of d[u]? d[u] d[v]+w(v,u)= δ(s,v)+w(v,u) What is the value of d[u ]? d[u ] d[v ]+w(v,u )= δ(s,v )+w(v,u ) Since u is in the shortest path of u: d[u ]<δ(s,u) Using the upper bound property: d[u]>δ(s,u) d[u ]<d[u] Contradiction! Priority Queue Q: <u,, u,.> (i.e., d[u]< <d[u ]< ) 5

26 Consider the graph: Example the distances are appropriately initialized all vertices are marked as being unvisited

27 Example Visit vertex 1 and update its neighbours, marking it as visited the shortest paths to, 4, and 5 are updated

28 Example The next vertex we visit is vertex 4 vertex don t update vertex < update vertex < update

29 Next, visit vertex Example vertex < update vertex 4 already visited vertex don t update vertex < update

30 Example Next, we have a choice of either 3 or 6 We will choose to visit 3 vertex < 8 update vertex don t update

31 We then visit 6 Example vertex don t update vertex < update

32 Example Next, we finally visit vertex 5: vertices 4 and 6 have already been visited vertex < 10 update vertex < 9 update vertex don t update

33 Example Given a choice between vertices 7 and 8, we choose vertex 7 vertices 5 has already been visited vertex don t update

34 Next, we visit vertex 8: Example vertex < 13 update

35 Example Finally, we visit the end vertex Therefore, the shortest path from 1 to 9 has length 11

36 Example We can find the shortest path by working back from the final vertex: 9, 8, 5, 3,, 1 Thus, the shortest path is (1,, 3, 5, 8, 9)

37 Example 3 37

38 Example 3 38

39 Example 3 39

40 Example 3 40

41 Example 3 41

42 Example 3 4

43 Example 3 43

44 Example 3 44

45 Example 4: Initialization Distance(source) = 0 0 A B Distance (all vertices but source) = C D E F 1 G Pick vertex in List with minimum distance. 45

46 Example 4: Update neighbors' distance 0 A B C D E Distance(B) = Distance(D) = 1 F 1 G 46

47 Example 4: Remove vertex with minimum distance 0 A B C D E F 1 G Pick vertex in List with minimum distance, i.e., D 47

48 Example 4: Update neighbors 0 A B C D E Distance(C) = 1 + = 3 Distance(E) = 1 + = 3 Distance(F) = = 9 Distance(G) = = 5 F 1 G

49 Example 4: Continued... Pick vertex in List with minimum distance (B) and update neighbors 0 A B C D E 3 5 F G Note : distance(d) not updated since D is already known and distance(e) not updated since it is larger than previously computed 49

50 Example 4: Continued... Pick vertex List with minimum distance (E) and update neighbors 0 A B C D E F 1 G 9 5 No updating 50

51 Example 4: Continued... Pick vertex List with minimum distance (C) and update neighbors 0 A B C D E Distance(F) = = 8 F 1 G

52 Example 4: Continued... Pick vertex List with minimum distance (G) and update neighbors 0 A B C D E Previous distance Distance(F) = min (8, 5+1) = 6 F 1 G 6 5 5

53 Example 4 (end) 0 A B C D E F 1 G 6 5 Pick vertex not in S with lowest cost (F) and update neighbors 53

54 Example 5: s=bwi 54

55 Example 5 55

56 Example 5 56

57 Example 5 57

58 Example 5 58

59 Negative weights Dijkstra fails on graphs with negative edges Example: Bringing z into S and performing edge relaxation invalidates the previously computed shorted path distance (14) to x S 59

COMP251: Single source shortest paths

COMP251: 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 information

Shortest Path Problems

Shortest Path Problems Shortet Path Problem How can we find the hortet route between two point on a road map? Model the problem a a graph problem: Road map i a weighted graph: vertice = citie edge = road egment between citie

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer 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 information

Minimum Spanning Trees

Minimum 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 information

Shortest Path Problem

Shortest 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 information

Single Source Shortest Path

Single 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 information

5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456

5.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 information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 20. Example. Shortest Paths Definitions

Taking 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 information

COT 6405 Introduction to Theory of Algorithms

COT 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 information

Lecture 18 Graph-Based Algorithms. CSE373: Design and Analysis of Algorithms

Lecture 18 Graph-Based Algorithms. CSE373: Design and Analysis of Algorithms Lecture 18 Graph-Baed Algorithm CSE: Deign and Anali of Algorithm Shortet Path Problem Modeling problem a graph problem: Road map i a weighted graph: vertice = citie edge = road egment between citie edge

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-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 information

Algorithms on Graphs: Part III. Shortest Path Problems. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

Algorithms 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 information

Introduction to Algorithms. Lecture 11

Introduction 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 information

Shortest path problems

Shortest 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 information

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

Introduction. 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 information

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24

4/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 information

from notes written mostly by Dr. Carla Savage: All Rights Reserved

from 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 information

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems

Chapter 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 information

Single Source Shortest Paths

Single 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 information

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

Introduction. 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 information

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

CS420/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 information

Single Source Shortest Path (SSSP) Problem

Single 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 information

Unit 2: Algorithmic Graph Theory

Unit 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 information

Lecture 11: Analysis of Algorithms (CS ) 1

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 information

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Graphs. 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 information

Single-Source Shortest Paths. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

Single-Source Shortest Paths. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Single-Source Shortest Paths CSE Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Terminology A network is a directed graph. We will use both terms interchangeably. The

More information

Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest 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 information

Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest 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 information

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths Part VI Graph algorithms Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths 1 Chapter 22 Elementary Graph Algorithms Representations of graphs

More information

Title. 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. 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 information

Minimum Spanning Tree

Minimum Spanning Tree Minimum Spanning Tree 1 Minimum Spanning Tree G=(V,E) is an undirected graph, where V is a set of nodes and E is a set of possible interconnections between pairs of nodes. For each edge (u,v) in E, we

More information

The Shortest Path Problem

The 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 information

Classical Shortest-Path Algorithms

Classical 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 information

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck

Theory 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 information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

Algorithm Design and Analysis

Algorithm 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 information

Introduction Single-source shortest paths All-pairs shortest paths. Shortest paths in graphs

Introduction 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 information

Week 12: Minimum Spanning trees and Shortest Paths

Week 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 information

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

Breadth-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 information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

Design and Analysis of Algorithms 演算法設計與分析. Lecture 13 December 18, 2013 洪國寶

Design 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 information

Dijkstra s Shortest Path Algorithm

Dijkstra 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 information

Shortest Path Algorithms

Shortest Path Algorithms Shortest Path Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Single Source Shortest Path Given: a directed or undirected graph G = (V,E) a source node s in V a weight function w: E

More information

Outline. Computer Science 331. Definitions: Paths and Their Costs. Computation of Minimum Cost Paths

Outline. 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 information

1 Dijkstra s Algorithm

1 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 information

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution

Taking 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 information

CS350: Data Structures Dijkstra s Shortest Path Alg.

CS350: 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 information

Algorithms for Data Science

Algorithms 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 information

All Shortest Paths. Questions from exercises and exams

All Shortest Paths. Questions from exercises and exams All Shortest Paths Questions from exercises and exams The Problem: G = (V, E, w) is a weighted directed graph. We want to find the shortest path between any pair of vertices in G. Example: find the distance

More information

Analysis of Algorithms, I

Analysis 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 information

Outlines: Graphs Part-2

Outlines: Graphs Part-2 Elementary Graph Algorithms PART-2 1 Outlines: Graphs Part-2 Graph Search Methods Breadth-First Search (BFS): BFS Algorithm BFS Example BFS Time Complexity Output of BFS: Shortest Path Breath-First Tree

More information

Single 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: 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 information

TIE Graph algorithms

TIE 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 information

CS 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 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 information

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

The 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 information

Week 11: Minimum Spanning trees

Week 11: Minimum Spanning trees Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,

More information

Algorithms for Data Science

Algorithms 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 information

Dijkstra s Algorithm

Dijkstra 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 information

24 Single-Source Shortest Paths

24 Single-Source Shortest Paths 4 Single-Source Shortest Paths Professor Patrick wishes to find the shortest possible route from Phoenix to Indianapolis. Given a road map of the United States on which the distance between each pair of

More information

Minimum Spanning Trees

Minimum Spanning Trees CSMPS 2200 Fall Minimum Spanning Trees Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 11/6/ CMPS 2200 Intro. to Algorithms 1 Minimum spanning trees Input: A

More information

Review of course COMP-251B winter 2010

Review of course COMP-251B winter 2010 Review of course COMP-251B winter 2010 Lecture 1. Book Section 15.2 : Chained matrix product Matrix product is associative Computing all possible ways of parenthesizing Recursive solution Worst-case running-time

More information

Lecture 6 Basic Graph Algorithms

Lecture 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 information

Outline. Computer Science 331. Analysis of Prim's Algorithm

Outline. Computer Science 331. Analysis of Prim's Algorithm Outline Computer Science 331 Analysis of Prim's Algorithm Mike Jacobson Department of Computer Science University of Calgary Lecture #34 1 Introduction 2, Concluded 3 4 Additional Comments and References

More information

Data Structures and Algorithms. Werner Nutt

Data Structures and Algorithms. Werner Nutt Data Structures and Algorithms Werner Nutt nutt@inf.unibz.it http://www.inf.unibz/it/~nutt Chapter 10 Academic Year 2012-2013 1 Acknowledgements & Copyright Notice These slides are built on top of slides

More information

Unit 5F: Layout Compaction

Unit 5F: Layout Compaction Course contents Unit 5F: Layout Compaction Design rules Symbolic layout Constraint-graph compaction Readings: Chapter 6 Unit 5F 1 Design rules: restrictions on the mask patterns to increase the probability

More information

Unit 3: Layout Compaction

Unit 3: Layout Compaction Unit 3: Layout Compaction Course contents Design rules Symbolic layout Constraint-graph compaction Readings: Chapter 6 Unit 3 1 Design rules: restrictions on the mask patterns to increase the probability

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J LECTURE 13 Graph algorithms Graph representation Minimum spanning trees Greedy algorithms Optimal substructure Greedy choice Prim s greedy MST algorithm Prof.

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J LECTURE 16 Greedy Algorithms (and Graphs) Graph representation Minimum spanning trees Optimal substructure Greedy choice Prim s greedy MST algorithm Prof. Charles

More information

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Tutorial. 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 information

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

CS200: 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 information

Dijkstra s Algorithm. Single source shortest paths for a directed acyclic graph

Dijkstra s Algorithm. Single source shortest paths for a directed acyclic graph Dijkstra s Algorithm Single source shortest paths for a directed acyclic graph Single-Source Shortest Paths We want to find the shortest paths between Binghamton and New York City, Boston, and Washington

More information

CSE 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 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 information

Shortest Paths. Shortest Path. Applications. CSE 680 Prof. Roger Crawfis. Given a weighted directed graph, one common problem is finding the shortest

Shortest 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 information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees Overview Problem A town has a set of houses and a set of roads. A road connects and only houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and

More information

Lecture 10: Analysis of Algorithms (CS ) 1

Lecture 10: Analysis of Algorithms (CS ) 1 Lecture 10: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 05, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 Topological Sort Strongly Connected Components 2

More information

Lecture I: Shortest Path Algorithms

Lecture I: Shortest Path Algorithms 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 201 1 / 28 Background

More information

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

CS 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 information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms, Lecture 1 /1/200 Introduction to Algorithms.04J/1.401J LECTURE 11 Graphs, MST, Greedy, Prim Graph representation Minimum spanning trees Greedy algorithms hallmarks. Greedy choice

More information

Introductory Computer Programming: Shortest Path Algorithms

Introductory Computer Programming: Shortest Path Algorithms Introductory Computer Programming: 2017-18 Shortest Path Algorithms Soumik Purkayastha MD-1710 Contents 1 Project Proposal 1 2 Report 3 2.1 Introduction........................................ 3 2.2 Basic

More information

Graph Representation

Graph Representation Graph Representation Adjacency list representation of G = (V, E) An array of V lists, one for each vertex in V Each list Adj[u] contains all the vertices v such that there is an edge between u and v Adj[u]

More information

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

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 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 information

Lecture #7. 1 Introduction. 2 Dijkstra s Correctness. COMPSCI 330: Design and Analysis of Algorithms 9/16/2014

Lecture #7. 1 Introduction. 2 Dijkstra s Correctness. COMPSCI 330: Design and Analysis of Algorithms 9/16/2014 COMPSCI 330: Design and Analysis of Algorithms 9/16/2014 Lecturer: Debmalya Panigrahi Lecture #7 Scribe: Nat Kell 1 Introduction In this lecture, we will further examine shortest path algorithms. We will

More information

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Dijkstra s algorithm for shortest paths when no edges have negative weight. Lecture 14 Graph Algorithms II 14.1 Overview In this lecture we begin with one more algorithm for the shortest path problem, Dijkstra s algorithm. We then will see how the basic approach of this algorithm

More information

Section authors: Hamilton Clower, David Scott, Ian Dundore.

Section authors: Hamilton Clower, David Scott, Ian Dundore. 2.6.1 Dijkstra s Algorithm Section authors: Hamilton Clower, David Scott, Ian Dundore. Strategy Specialized 1.4 Greedy 1.7 Edge Comparison Based 3.2 Single-Source Shortest-Paths 3.7 Dijkstras Algorithm

More information

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Greedy Algorithms. At each step in the algorithm, one of several choices can be made. Greedy Algorithms At each step in the algorithm, one of several choices can be made. Greedy Strategy: make the choice that is the best at the moment. After making a choice, we are left with one subproblem

More information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

MST & Shortest Path -Prim s -Djikstra s

MST & Shortest Path -Prim s -Djikstra s MST & 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 by some edges. - A graph can have one or more

More information

Algorithm Design and Analysis

Algorithm 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 information

CS 561, Lecture 10. Jared Saia University of New Mexico

CS 561, Lecture 10. Jared Saia University of New Mexico CS 561, Lecture 10 Jared Saia University of New Mexico Today s Outline The path that can be trodden is not the enduring and unchanging Path. The name that can be named is not the enduring and unchanging

More information

Announcements Problem Set 5 is out (today)!

Announcements Problem Set 5 is out (today)! CSC263 Week 10 Announcements Problem Set is out (today)! Due Tuesday (Dec 1) Minimum Spanning Trees The Graph of interest today A connected undirected weighted graph G = (V, E) with weights w(e) for each

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 10 Implementing MST Algorithms Adam Smith Minimum spanning tree (MST) Input: A connected undirected graph G = (V, E) with weight function w : E R. For now, assume

More information

Artificial Intelligence

Artificial 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 information

Algorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University

Algorithms. 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 information

CS 4349 Lecture October 23rd, 2017

CS 4349 Lecture October 23rd, 2017 CS 4349 Lecture October 23rd, 2017 Main topics for #lecture include #minimum_spanning_trees and #SSSP. Prelude Homework 7 due Wednesday, October 25th. Don t forget about the extra credit. Minimum Spanning

More information

MA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati

MA 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 information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS 4 Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

Lecture Notes for Chapter 23: Minimum Spanning Trees

Lecture Notes for Chapter 23: Minimum Spanning Trees Lecture Notes for Chapter 23: Minimum Spanning Trees Chapter 23 overview 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

More information

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Dijkstra 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 information

Chapter 25: All-Pairs Shortest-Paths

Chapter 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 information

Lecture 5: Graph algorithms 1

Lecture 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 information