shortest paths
play

Shortest Paths Todays announcements: PA3 due 29 Nov 23:59 Final - PowerPoint PPT Presentation

Shortest Paths Todays announcements: PA3 due 29 Nov 23:59 Final Exam, 10 Dec 12:00, OSBO A Todays Plan: Dijkstras shortest path algorithm 22 7 3 10 s 4 6 8 10 12 4 5 8 7 16 12 8 4 0 Find the shortest path


  1. Shortest Paths Today’s announcements: ◮ PA3 due 29 Nov 23:59 ◮ Final Exam, 10 Dec 12:00, OSBO A Today’s Plan: ◮ Dijkstra’s shortest path algorithm 22 7 3 10 s 4 6 8 10 12 4 5 8 7 16 12 8 4 0 Find the shortest path 2 4 8 16 from s to t . 45 4 7 23 6 1 2 3 5 3 8 1 8 9 3 1 4 1 t 1 / 6

  2. Dijkstra’s Single-Source Shortest Path Algorithm (another breadth-first search with a priority queue) 3 10 A B C Assume edge weights are non-negative. -5 1 2 D E Dijkstra’s algorithm is a greedy algorithm (it makes the current best choice without considering future consequences). Intuition: Find shortest paths from source in order of length. ◮ Start at the source vertex (shortest path length = 0) ◮ The next shortest path extends some already discovered shortest path by one edge. Why? ◮ Find it (by considering all one-edge extensions) and repeat. 2 / 6

  3. Dijkstra’s Algorithm Pseudocode 1. Unmark all vertices 2. Initialize the dist to each vertex to ∞ 3. Initialize the dist to the source to 0 4. While there are unmarked vertices left in the graph ◮ Select the unmarked vertex v with the lowest dist ◮ Mark v by setting SPlength=dist ◮ For each edge ( v , w ) ◮ dist( w ) = min(dist( w ), dist( v ) + weight of ( v , w )) 2 2 C B F 1 1 3 9 4 A 10 2 H 2 8 1 1 D E G 7 4 vertex A B C D E F G H dist SPlength 3 / 6

  4. Correctness: The Cloud Proof u Q s P y cloud ◮ Assume Dijkstra’s algorithm finds the correct shortest path to the first k vertices it visits (the cloud ). ◮ But it fails on the ( k + 1)st vertex u . ◮ So there is some shorter path, P , from s to u . ◮ Path P must contain a first vertex y not in the cloud. ◮ But since the path, Q , to u is the shortest path out of the cloud, the path on P upto y must be at least as long as Q . ◮ Thus the whole path P is at least as long as Q . Contradiction (What do we use in that last step?) 4 / 6

  5. Data Structures for Dijkstra’s Algorithm n times: Select the unmarked vertex with the lowest dist. removeMin m times: dist( w ) = min { dist( w ), dist( v ) + weight of ( v , w ) } decreasePriority Runtime: (adjacency matrix or adjacency list?) 5 / 6

  6. Fibonacci Heaps ◮ Another implementation of a Priority Queue ◮ Amortized O (1) time for decreasePriority. ◮ O (log n ) time for removeMin Dijkstra’s uses n removeMins and m decreasePriorities Runtime with Fibonacci heaps: 6 / 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend