Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 213 – Large Scale Programming. Minimum Spanning Tree (MST)  Spanning subgraph  Subgraph w/ all vertices ORD PIT ATL STL DEN DFW DCA 10 1 9 8 6 3.

Similar presentations


Presentation on theme: "CSC 213 – Large Scale Programming. Minimum Spanning Tree (MST)  Spanning subgraph  Subgraph w/ all vertices ORD PIT ATL STL DEN DFW DCA 10 1 9 8 6 3."— Presentation transcript:

1 CSC 213 – Large Scale Programming

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

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

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

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

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

7 Partition Property  Given partitioning of vertices in a graph exactly1  Required that each vertex in exactly 1 partition  Use smallest edge to connect each of the  To complete following MST, can use either f or e 7 4 2 8 5 7 3 9 8

8 Kruskal’s Algorithm  Similar to Prim-Jarnik, including finding MST  Also like Prim-Jarnik, adds edges greedily Edge s  But Kruskal processes Edge s using PriorityQueue  Check if Edge makes cycle before adding to MST  No cycles in an MST, so add Edge if 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 Edge s  But Kruskal processes Edge s using PriorityQueue  Check if Edge makes cycle before adding to MST  No cycles in an MST, so add Edge if 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 Edge s  But Kruskal processes Edge s using PriorityQueue  Check if Edge makes cycle before adding to MST  No cycles in an MST, so add Edge if 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 Set holds tree from graph  Methods supporting Set s defined by Partition  find(u) : find and returns Set containing u  union(p,r) : replace p & r with their union  makeSet(u) : creates Set for u & adds to Partition

12 Kruskal’s Algorithm Algorithm KruskalMST(Graph G) Q  new PriorityQueue() 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 867 2704 1258 849 144 740 1391 946 1090 1121 2342 1846 621 802 1464 1235 337 BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO 187

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

35 For Next Lecture


Download ppt "CSC 213 – Large Scale Programming. Minimum Spanning Tree (MST)  Spanning subgraph  Subgraph w/ all vertices ORD PIT ATL STL DEN DFW DCA 10 1 9 8 6 3."

Similar presentations


Ads by Google