Cinda Heeren / Geoffrey Tien

Slides:



Advertisements
Similar presentations
Chapter 9: Graphs Shortest Paths
Advertisements

Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
Graphs. John Edgar  Understand graph terminology  Implement graphs using  Adjacency lists and  Adjacency matrices  Perform graph searches  Depth.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
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.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Shortest Path Problem For weighted graphs it is often useful to find the shortest path between two vertices Here, the “shortest path” is the path that.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
SPANNING TREES Lecture 21 CS2110 – Spring
Minimum Spanning Trees
COSC 2007 Data Structures II Chapter 14 Graphs III.
CSE 326: Data Structures Lecture #20 Graphs I.5 Alon Halevy Spring Quarter 2001.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
CSC 213 – Large Scale Programming. Today’s Goals  Discuss what is meant by weighted graphs  Where weights placed within Graph  How to use Graph ’s.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
CSE 326: Data Structures Lecture #23 Dijkstra and Kruskal (sittin’ in a graph) Steve Wolfman Winter Quarter 2000.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Shortest Paths.
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
CSE373: Data Structures & Algorithms Lecture 19: Spanning Trees
Chapter 7: Greedy Algorithms
Csc 2720 Instructor: Zhuojun Duan
C.Eng 213 Data Structures Graphs Fall Section 3.
Minimum Spanning Trees and Shortest Paths
Introduction (with applications) ADT & terminology
Shortest Path Problems
Shortest Path Problems
Short paths and spanning trees
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Shortest Paths.
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
CSE373: Data Structures & Algorithms Lecture 18: Dijkstra’s Algorithm
CSE 373: Data Structures and Algorithms
Graphs.
Chapter 11 Graphs.
Shortest Path Problems
CSE373: Data Structures & Algorithms Lecture 19: Spanning Trees
Shortest Path Algorithms
Based on slides of Dan Suciu
Directed Graph Algorithms
Directed Graph Algorithms
CSE 373: Data Structures and Algorithms
Minimum Spanning Tree.
Weighted Graphs & Shortest Paths
Shortest Path Problems
CSE332: Data Abstractions Lecture 17: Shortest Paths
CSE 373 Data Structures and Algorithms
Shortest Path Problems
CSC 380: Design and Analysis of Algorithms
Graph Algorithms: Shortest Path
Shortest Paths.
CSE 417: Algorithms and Computational Complexity
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Richard Anderson Spring 2016
Chapter 9: Graphs Shortest Paths
Directed Graphs (Part II)
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:

Cinda Heeren / Geoffrey Tien Shortest Paths Dijkstra's Algorithm April 06, 2018 Cinda Heeren / Geoffrey Tien

Cinda Heeren / Geoffrey Tien Announcements PA4 due Apr.09 Geoff's office hours next week Monday & Wednesday, 10:00 – 14:00 Final exam Thursday, April 12 15:30 – 18:00 (150 minutes) SRC A, B, C Assigned seating by name, please be seated in your correct spot! April 06, 2018 Cinda Heeren / Geoffrey Tien

Single-source shortest path Given a graph 𝐺= 𝑉,𝐸 and a vertex 𝑠∈𝑉, find the shortest path from 𝑠 to every vertex in 𝑉 Variations Weighted vs unweighted Cyclic vs acyclic Positive weights only vs negative weights allowed Multiple weight types to optimize April 06, 2018 Cinda Heeren / Geoffrey Tien

Single-Source Shortest Path Un/directed, weighted graphs, no negative cycles What is the least cost path from one vertex to another? For weighted graphs, this is the path that has the smallest sum of its edge weights A 1 4 B C 5 3 2 E 1 5 D 8 1 F 2 G The shortest path between B and G is: B-D-E-F-G (7) and not B-G (8) April 06, 2018 Cinda Heeren / Geoffrey Tien

Cinda Heeren / Geoffrey Tien Dijkstra's Algorithm Classic algorithm for solving shortest path in weighted graphs without negative weights A greedy algorithm Best local choice is made at each step, without considering future consequences Intuition: Shortest path from source vertex to itself is 0 Cost of going to adjacent nodes is at most edge weights Cheapest of these must be shortest path to that node Update paths for new node and continue picking shortest path April 06, 2018 Cinda Heeren / Geoffrey Tien

Cinda Heeren / Geoffrey Tien Dijkstra's Algorithm Initialize the cost of reaching each vertex to ∞ Initialize the cost of the source to 0 While there are unvisited vertices left in the graph Select the unvisited vertex with the lowest cost: 𝑢 Mark 𝑢 as visited, and note the vertex 𝑣 which was used to reach 𝑢 For each vertex 𝑤 which is adjacent to 𝑢 𝑤's cost = min(𝑤's old cost, 𝑢's cost + cost of (𝑢,𝑤)) And note the "predecessor" vertex which can be used to reach 𝑤 with the lowest cost April 06, 2018 Cinda Heeren / Geoffrey Tien

Dijkstra's Algorithm Example: directed graph A B C D E F G H 2 4 7 9 1 8 10 3 Source node: C Priority queue: Vertex Cost Predecessor A B C D E F G H Visited Cost Predecessor Note that we need access to arbitrary elements in this prQ in order to update April 06, 2018 Cinda Heeren / Geoffrey Tien

Cinda Heeren / Geoffrey Tien Dijkstra's Algorithm Undirected graph 2 2 B A F 3 H Source node: C 1 9 2 10 1 4 C G Priority queue: 2 8 Vertex Cost Predecessor A B C D E F G H 1 D E 7 Visited Cost Predecessor April 06, 2018 Cinda Heeren / Geoffrey Tien

Dijkstra's algorithm C, 0, C B, 1, C D, 2, C A, 3, B F, 3, B G, 5, F Retrieving the shortest path vertex, cost, predecessor Once the results array is complete paths from the start vertex can be retrieved Done by looking up the end vertex (the vertex to which one is trying to find a path) and backtracking through parent vertices to the start For example to find a path to vertex E backtrack through: E, G, F, B, C Note: there should be some efficient way to search the results array for a vertex and this path is in reverse order! C, 0, C B, 1, C D, 2, C A, 3, B F, 3, B G, 5, F H, 6, F E, 6, G April 06, 2018 Cinda Heeren / Geoffrey Tien

Correctness VISITED VERTICES The cloud proof, informally 𝑤 𝑦 𝑢 𝑠 𝑣 𝑥 Vertices in the cloud have a known shortest path, and 𝑤 is the next vertex to add according to the priority queue Proof by induction, note that negative edge weights wreck this proof! April 06, 2018 Cinda Heeren / Geoffrey Tien

Data structures for Dijkstra's algorithm Selecting unvisited node with the minimum cost Priority queue / min-heap! Building initial heap is 𝑂 𝑉 RemoveMin executed 𝑉 times, total 𝑂 𝑉 log 𝑉 Each of 𝐸 edges has to be processed once Looking up (and changing) the current cost of a vertex in a heap takes 𝑂 𝑉 for an unindexed heap (𝑂 1 if the heap is indexed) The heap property needs to be preserved after a change for an additional cost of 𝑂 log 𝑉 The total cost is 𝑉 + 𝑉 log 𝑉 + 𝐸 𝑉 + log 𝑉 Or, 𝑂 𝑉 log 𝑉 + 𝐸 𝑉 If the heap is indexed the cost is 𝑂 𝑉 + 𝐸 log 𝑉 April 06, 2018 Cinda Heeren / Geoffrey Tien

Cinda Heeren / Geoffrey Tien Exercise Given the following undirected, weighted graph, use Dijkstra's algorithm to determine the cost and vertex sequence of a shortest path from A to I. A 12 B 8 9 9 C 10 8 5 5 D 6 E F 14 G 3 4 H 12 7 4 9 I 7 J 8 K April 06, 2018 Cinda Heeren / Geoffrey Tien

Readings for this lesson Carrano & Henry Chapter 20.4.4 (Shortest path) Congratulations, you're done! April 06, 2018 Cinda Heeren / Geoffrey Tien