1 / 12

Some Applications: Moving Around Washington

Some Applications: Moving Around Washington. What’s the fastest way from Seattle to Spokane?. Answer:. Use Dijkstra!. Some Applications: Communication in Washington. What’s the cheapest inter-city network?. New problem for today. 4. 7. 9. 2. 1. 5. Spanning Tree.

Download Presentation

Some Applications: Moving Around Washington

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Some Applications:Moving Around Washington What’s the fastest way from Seattle to Spokane? Answer: Use Dijkstra!

  2. Some Applications:Communication in Washington What’s the cheapest inter-city network? New problem for today

  3. 4 7 9 2 1 5 Spanning Tree Spanning tree: a subset of the edges from a connected graph that… • touches all vertices in the graph (spans the graph) • forms a tree (is connected and contains no cycles) Minimum spanning tree: the spanning tree with the least total edge cost. Which is the minimum? (the middle)

  4. Two Different Algorithms Prim’s Algorithm Almost identical to Dijkstra’s Kruskals’s Algorithm Completely different! One node, grow greedily Forest of MSTs, Union them together. I wonder how to union…

  5. Prim’s Algorithm for Minimum Spanning Trees A node-oriented greedy algorithm (builds an MST by greedily adding nodes) Select a node to be the “root” and mark it as known While there are unknown nodes left in the graph Select the unknown node n with the smallest cost from some known node m Mark n as known Add (m, n) to our MST Update cost of all nodes adjacent to n Cost == edge weight only. Use priority queue Runtime: Proof: Same as Dijkstra: O(ElogV) Same as Dijkstra

  6. 2 2 3 B A F H 2 1 1 4 10 9 G 4 C 8 2 D E 7 Prim’s Algorithm In Action Start with A

  7. Kruskal’s Algorithm for Minimum Spanning Trees An edge-oriented greedy algorithm (builds an MST by greedily adding edges) Initialize all vertices to unconnected While there are still unmarked edges Pick the lowest cost edge e = (u, v) and mark it If u and v are not already connected, add e to the minimum spanning tree and connect u and v Sound familiar? Maze use random edge order.Otherwise the same!

  8. 2 2 3 B A F H 2 1 1 4 10 9 G 4 C 8 2 D E 7 Kruskal’s Algorithm In Action

  9. Play at Home with Prim 1 F 6 A B H 7 5 3 2 11 12 9 C G 4 10 13 D 4 E • Starting at node A, find the MST using Prim’s method. • (continue on next slide)

  10. Play at Home with Kruskal 1 F 6 A B H 7 5 3 2 11 12 9 C G 4 10 13 D 4 E • Now find the MST using Kruskal’s method. • Under what conditions will these methods give the same result? • What data structures should be used for Kruskal’s? Running time?

  11. Proof of Correctness We already showed this finds a spanning tree: That was part of our definition of a good maze. Proof by contradiction that Kruskal’s finds the minimum: Assume another spanning tree has lower cost than Kruskal’s Pick an edge e1 = (u, v) in that tree that’s not in Kruskal’s Kruskal’s tree connects u’s and v’s sets with another edge e2 But, e2 must have at most the same cost as e1! So, swap e2 for e1 (at worst keeping the cost the same) Repeat until the tree is identical to Kruskal’s: contradiction! QED: Kruskal’s algorithm finds a minimum spanning tree. (contradicts that other tree is better)

  12. Kruskal’s Implementation Initialize all vertices to unconnected While there are still unmarked edges Pick the lowest cost edge e = (u, v) and mark it If u and v are not already connected, add e to the minimum spanning tree and connect u and v E * deleteMin 2E * find + + V * union What data structures? Running time? Priority queue + disjoint sets O( ElogE + E~O(1)) = O(ElogE) = O(ElogV)b/c log E < logV2 = 2logV

More Related