Recitation 10. Shortest Paths Announcements. ShortLab has been released, and is due Friday afternoon. It s worth 125 points.

Similar documents
Recitation 13. Minimum Spanning Trees Announcements. SegmentLab has been released, and is due Friday, November 17. It s worth 135 points.

1 Dijkstra s Algorithm

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

lecture29: Shortest Path Algorithms

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

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

Recitation 11. Graph Contraction and MSTs Announcements. SegmentLab has been released, and is due Friday, April 14. It s worth 135 points.

CMPSC 250 Analysis of Algorithms Spring 2018 Dr. Aravind Mohan Shortest Paths April 16, 2018

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

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

Implementations. Priority Queues. Heaps and Heap Order. The Insert Operation CS206 CS206

Recitation 13. Priority Queues and Hashing Announcements. PASLLab is due this Friday, May 5. The final exam is on Friday, May 13.

1 The Shortest Path Problem

CS 3410 Ch 14 Graphs and Paths

CMPUT 396 Sliding Tile Puzzle

Recitation 12. Dynamic Programming Announcements. SegmentLab has been released and is due Apr 14.

Single Source Shortest Path

Lecture 11: Analysis of Algorithms (CS ) 1

The Shortest Path Problem

Dijkstra s Shortest Path Algorithm

Algorithm Design and Analysis

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

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

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

Priority Queues. Meld(Q 1,Q 2 ) merge two sets

CSE 373: Data Structures and Algorithms

Week 12: Minimum Spanning trees and Shortest Paths

Single Source Shortest Path (SSSP) Problem

Shortest Path Problem

CS171 Introduction to Computer Science II. Graphs

Week 11: Minimum Spanning trees

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

Search: Advanced Topics and Conclusion

Heuristic Functions. Lecture Heuristic Search. Stefan Edelkamp

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s

Practice Problems for the Final

Institutionen för datavetenskap Department of Computer and Information Science

Algorithms in a Nutshell. Session 4 Recap Algorithm Themes 11:20 11:40

CS4800: Algorithms & Data Jonathan Ullman

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

ME/CS 132: Advanced Robotics: Navigation and Vision

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

Algorithm Design and Analysis

Algorithms for Data Science

Data Structure Lecture#24: Graphs 2 (Chapter 11) U Kang Seoul National University

Algorithms and Data Structures 2014 Exercises and Solutions Week 9

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

Search: Advanced Topics and Conclusion

Single Source Shortest Paths

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

Algorithms for Minimum Spanning Trees

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

TA: Jade Cheng ICS 241 Recitation Lecture Notes #12 November 13, 2009

SHORTEST PATHS. Weighted Digraphs. Shortest paths. Shortest Paths BOS ORD JFK SFO LAX DFW MIA

Heuristic Search and Advanced Methods

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

CS 106X, Lecture 23 Dijkstra and A* Search

Announcements. Solution to Assignment 1 is posted Assignment 2 is available Video automatically uploaded (see web page)

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

CSE 502 Class 23. Jeremy Buhler Steve Cole. April BFS solves unweighted shortest path problem. Every edge traversed adds one to path length

A and Branch-and-Bound Search

Single Source Shortest Path: The Bellman-Ford Algorithm. Slides based on Kevin Wayne / Pearson-Addison Wesley

1 i n (p i + r n i ) (Note that by allowing i to be n, we handle the case where the rod is not cut at all.)

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

Solution. violating the triangle inequality. - Initialize U = {s} - Add vertex v to U whenever DIST[v] decreases.

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

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

Recitation 1. Scan. 1.1 Announcements. SkylineLab has been released, and is due Friday afternoon. It s worth 125 points.

CS 4349 Lecture October 23rd, 2017

Final Exam Solutions

CS61BL. Lecture 5: Graphs Sorting

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

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

CSE 326: Data Structures Dijkstra s Algorithm. James Fogarty Autumn 2007

CS350: Data Structures Dijkstra s Shortest Path Alg.

Route planning / Search Movement Group behavior Decision making

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

COMP251: Single source shortest paths

Dijkstra s Algorithm and Priority Queue Implementations. CSE 101: Design and Analysis of Algorithms Lecture 5

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

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

Algorithms for Data Science

Shortest path problems

ASYMPTOTIC COMPLEXITY

Minimum Spanning Trees

Dr. Alexander Souza. Winter term 11/12

Lecture 17: Weighted Graphs, Dijkstra s Algorithm. Courtesy of Goodrich, Tamassia and Olga Veksler

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

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

Announcements Problem Set 5 is out (today)!

TIE Graph algorithms

Shortest Path Algorithms

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

Topological Sort. Here a topological sort would label A with 1, B and C with 2 and 3, and D with 4.

Description of The Algorithm

Approximate path planning. Computational Geometry csci3250 Laura Toma Bowdoin College

CSE373: Data Structures & Algorithms Lecture 9: Priority Queues and Binary Heaps. Linda Shapiro Spring 2016

CS/COE

Transcription:

Recitation 10 Shortest Paths 10.1 Announcements ShortLab has been released, and is due Friday afternoon. It s worth 125 points. SegmentLab will be released on Friday. 57

58 RECITATION 10. SHORTEST PATHS 10.2 Dijkstra s Algorithm For this section, we ll be using Dijkstra s algorithm as implemented in the textbook. It is also given here as a refresher. Algorithm 10.1. Dijkstra s Algorithm 1 Dijkstra (G,s) = 2 let 3 dijkstra (X,Q) = 4 case PQ.deleteMin Q of 5 (NONE, _) 6 (SOME (d, v), Q ) 7 if v X then dijkstra (X,Q ) else 8 let 9 X = X {v d} 10 relax (Q,(u,w)) = PQ.insert (Q,(d + w,u)) 11 Q = iterate relax Q 12 in (N + G (v)) 13 dijkstra (X,Q ) 14 end 15 in 16 dijkstra ({}, PQ.singleton (0,s)) 17 end

10.2. DIJKSTRA S ALGORITHM 59 Task 10.2. Run Dijkstra s algorithm on the following, starting from GHC. Trace the process by writing the most recently popped vertex and the contents of the priority queue immediately before each deletemin operation. Also write the returned mapping of each vertex to its shortest path distance.

60 RECITATION 10. SHORTEST PATHS Task 10.3. Consider the following simple modification to Dijkstra s algorithm: When relaxing the neighbors of a vertex, we only insert a neighbor into the priority queue if it has not already been visited. Does this modification improve the worst-case cost bounds of Dijkstra s algorithm? Task 10.4. Priority queues sometimes support a decreasekey operation which attempts to decrease the priority associated with some value. For example, in the priority queue {(15, A), (42, B)}, we could apply decreasekey on B with a new priority of 11 to get back the priority queue {(11, B), (15, A)}. If the newly specified priority is greater than the original, then this operation simply does nothing. Suppose that you are given a priority queue which supports insert and decreasekey in constant time, and deletemin in O(log Q ) time. a Describe how to use this data structure to improve the asymptotic performance of Dijkstra s algorithm. You may assume the graph is enumerated. a These bounds are supported by implementations such as Fibonacci and Brodal heaps.

10.3. A* 61 10.3 A* Dijkstra s algorithm computes shortest paths between the source and every other vertex in the graph. But what if we only care about the shortest path to a specific target vertex? In the example graph given above, if you are trying to get from GHC to BH, you intuitively know that the shortest path probably doesn t pass through the UC. As you work your way towards the goal, you are guided by an internal heuristic which helps you estimate how far each building is from BH and choose the most promising option. We can apply a similar approach to Dijkstra s algorithm. At each step, we d like to visit the most promising candidate among the vertices in the frontier. To determine how promising a candidate is, we need an estimate of how far that candidate is from the destination. Specifically, we ll assume we have a heuristic function h : V R + which maps vertices v to an estimate of the length of the shortest path between v and the destination. The A* algorithm is identical to Dijkstra s except that it orders its priority queue by d(v) + h(v) rather than by d(v), and terminates as soon as it finds the target. We also need to explicitly store the distance to each vertex in the priority queue. Here is the code: Algorithm 10.5. A* search with a consistent heuristic. 1 A h (G,s,t) = 2 let 3 search (X,Q) = 4 case PQ.deleteMin Q of 5 (NONE, _) 6 (SOME (_,(v,d)), Q ) 7 if v = t then d else 8 if v X then search (X,Q ) else 9 let 10 X = X {v d} 11 relax (Q,(u,w)) = PQ.insert (Q,(d+w+h(u),(u,d+w))) 12 Q = iterate relax Q 13 in (N + G (v)) 14 search (X,Q ) 15 end 16 in 17 search ({}, PQ.singleton (h(s),(s,0))) 18 end To visualize the difference between using (target-specific) Dijkstra and A*, visit this link. In order to ensure correctness, we need h to be consistent, meaning that for every two vertices u and v, h(u) δ(u, v)+h(v) where δ(u, v) is the shortest path from u to v. Furthermore,

62 RECITATION 10. SHORTEST PATHS the heuristic value of the destination must be 0: h(t) = 0. As an exercise, try proving that A* always finds an optimal path when using a consistent heuristic. It turns out that all consistent heuristics are also admissible, meaning that for every v, h(v) δ(v, t). The opposite is not always true. Task 10.6. Give an example of a consistent heuristic which causes A* to perform identically to Dijkstra s algorithm up until the point it visits the target. Task 10.7. Suppose we use h(v) = δ(v, t). Argue that A* visits exactly the vertices on the shortest path between s and t, and no others. (Assume a unique shortest path from s to t.) Remark 10.8. When searching a Euclidean space (where each vertex is a point in that space), a simple and effective heuristic is Euclidean distance. You should convince yourself that this heuristic is consistent.

10.4. ADDITIONAL EXERCISES 63 10.4 Additional Exercises Exercise 10.9. Design a consistent heuristic for the example graph given at the beginning of this recitation and run A* with that heuristic. Take note of how many vertices are left unvisited. Exercise 10.10. Prove that for any consistent heuristic h, A* returns the shortest path between the source and target. Exercise 10.11. Give an example of a small graph along with an admissible heuristic which is inconsistent. Exercise 10.12. Prove that any consistent heuristic is also admissible. Exercise 10.13. A simple modification of A* is called weighted-a*. In this algorithm, we take an additional parameter w 1.0 and order the priority queue by d(v)+w h(v). This has the tendency to make A* more directed towards the goal, further reducing the number of vertices visited at the cost of producing a potentially non-optimal solution. Prove that weighted-a* with weight w finds a path to the destination of length within a factor of w of the optimal path.

64 RECITATION 10. SHORTEST PATHS.