1 / 35

Lecture 35: Spanning Trees

CSC 213 – Large Scale Programming. Lecture 35: Spanning Trees. Minimum Spanning Tree (MST). Spanning subgraph Subgraph w/ all vertices. ORD. 10. 1. PIT. DEN. 6. 7. 9. 3. DCA. STL. 4. 5. 8. 2. DFW. ATL. Minimum Spanning Tree (MST). Spanning subgraph

casey
Télécharger la présentation

Lecture 35: Spanning Trees

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. CSC 213 – Large Scale Programming Lecture 35:Spanning Trees

  2. Minimum Spanning Tree (MST) • Spanning subgraph • Subgraph w/ all vertices ORD 10 1 PIT DEN 6 7 9 3 DCA STL 4 5 8 2 DFW ATL

  3. Minimum Spanning Tree (MST) • Spanning subgraph • Subgraph w/ all vertices ORD 10 1 PIT DEN 6 7 9 3 DCA STL 4 5 8 2 DFW ATL

  4. Minimum Spanning Tree (MST) • Spanning subgraph • Subgraph w/ all vertices • Spanning tree • Combinesspanning subgraph+ tree ORD 10 1 PIT DEN 6 7 9 3 DCA STL 4 5 8 2 DFW ATL

  5. Minimum Spanning Tree (MST) • Spanning subgraph • Subgraph w/ all vertices • Spanning tree • Combinesspanning subgraph+ tree • MST • Spanning tree which minimizes sum of edge weights ORD 10 1 PIT DEN 6 7 9 3 DCA STL 4 5 8 2 DFW ATL

  6. f f 8 8 4 4 9 9 6 6 2 2 3 3 e e 7 7 8 8 7 7 No Cycles in MST • Edge in MST cheaper than one making cycle • Assume there exists an edge enot in MST • Cycle,C, occurs after adding e to min. spanning tree • Assume that finCheavier than e • Shrink MST using eand dropping f from C

  7. Partition Property • Given partitioning of vertices in a graph • Required that each vertex in exactly1 partition • Use smallest edge to connect each of the • To complete following MST, can use either fore 7 4 9 5 2 8 3 8 7

  8. Kruskal’s Algorithm • Similar to Prim-Jarnik, including finding MST • Also like Prim-Jarnik, adds edges greedily • But Kruskal processes Edgesusing PriorityQueue • Check ifEdgemakes cyclebefore adding to MST • No cycles in an MST, so addEdgeif no cycle occurs • Detecting cycles hard, however

  9. Kruskal’s Algorithm • Similar to Prim-Jarnik, including finding MST • Also like Prim-Jarnik, adds edges greedily • But Kruskal processes Edgesusing PriorityQueue • Check ifEdgemakes cyclebefore adding to MST • No cycles in an MST, so addEdgeif no cycle occurs • Detecting cycles hard, however

  10. Kruskal’s Algorithm • Similar to Prim-Jarnik, including finding MST • Also like Prim-Jarnik, adds edges greedily • But Kruskal processes Edgesusing PriorityQueue • Check ifEdgemakes cyclebefore adding to MST • No cycles in an MST, so addEdgeif no cycle occurs • Detecting cycles hard, however

  11. Structure for Kruskal’s Algorithm • Kruskal’s needs to maintain collection of trees • Accept Edge connecting 2 trees & reject it otherwise • Data structure named Partition relied upon • Store disjoint Set instances within a Partition • For Kruskal’s, each Setholds tree from graph • Methods supporting Sets defined byPartition • find(u):find and returns Set containing u • union(p,r):replace p & rwith their union • makeSet(u): creates Set for u & adds to Partition

  12. Kruskal’s Algorithm AlgorithmKruskalMST(Graph G) Q  newPriorityQueue() T new Graph() P new Partition() for (Vertex v : G.vertices()) P.makeSet(v) T.insertVertex(v) for (Edge e : G.edges()) Q.insert(e.getWeight(), e); while (T.numEdges() < T.numVertices()-1) Edge e = Q.removeMin().value() Assign u, v to G.endpoints(e) if P.find(u)  P.find(v) T.insertEdge(e) P.union(P.find(u),P.find(v)) return T

  13. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  14. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  15. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  16. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  17. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  18. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  19. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  20. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  21. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  22. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  23. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  24. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  25. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  26. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  27. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  28. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  29. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  30. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  31. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  32. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  33. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  34. Kruskal Example 2704 BOS 867 849 PVD ORD 187 740 1846 144 JFK 621 184 802 1258 SFO 1464 BWI 1391 1090 337 946 DFW 1235 LAX 1121 MIA 2342

  35. For Next Lecture • Weekly assignment available on Angel • Due at special time: before next Monday’s quiz • Programming assignment #3 designs due today • Graph Quiz will be on Monday • Started before test, so could include implementations • Bring notes, templates, & anything else you want • Weekly assignment question review highly encouraged

More Related