minimum spanning tree
play

Minimum Spanning Tree Todays announcements: PA3 due 5 April 11:59p - PowerPoint PPT Presentation

Minimum Spanning Tree Todays announcements: PA3 due 5 April 11:59p Final Exam, 12 April 7:00p, SRC A & B 5 Todays Plan: 6 Prims algorithm 2 Dijkstras shortest path algorithm 7 2 Partition Property A cut is a


  1. Minimum Spanning Tree Today’s announcements: ◮ PA3 due 5 April 11:59p ◮ Final Exam, 12 April 7:00p, SRC A & B 5 Today’s Plan: 6 ◮ Prim’s algorithm 2 ◮ Dijkstra’s shortest path algorithm 7 2 Partition Property A cut is a set of edges whose removal disconnects G . Any edge that is a smallest weight edge in a cut is in some minimum spanning tree. 1 / 8

  2. Prim’s Minimum Spanning Tree Algorithm (i.e., Breadth-first search with a priority queue) Suppose I have an MST for a connected subgraph of G . What edge (and vertex) should I add next? 15 c b 16 10 5 5 2 d 13 11 a e 17 12 12 2 16 8 f h 4 g 9 2 / 8

  3. Prim’s Minimum Spanning Tree Algorithm (i.e., Breadth-first search with a priority queue) Prim(G) 8 c b for each vertex v 9 5 4 unmark v; d[v]=infinity 6 2 d 8 PQ.insert(v,d[v]) a e 3 6 while PQ is not empty 7 v = PQ.removeMin() f mark v // add v to MST v ’s priority is edge weight for each edge (v,w) to closest tree vertex from v if (w is unmarked && weight(v,w) < d[w]) PQ Adj. Matrix Adj. List d[w]=weight(v,w) Θ( n 2 ) Θ( n 2 ) array parent[w] = v Θ( n 2 + m log n ) heap Θ( m log n ) decreasePrior(w,d[w]) Which is best? 3 / 8

  4. Dijkstra’s Single-Source Shortest Path (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. 4 / 8

  5. 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 with 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 5 / 8

  6. 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 did I use in that last step?) 6 / 8

  7. 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 ) } decreasePrior Runtime: (adjacency matrix or adjacency list?) 7 / 8

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

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