CSC 213 – Large Scale Programming
Minimum Spanning Tree (MST) Spanning subgraph Subgraph w/ all vertices ORD PIT ATL STL DEN DFW DCA
Minimum Spanning Tree (MST) Spanning subgraph Subgraph w/ all vertices ORD PIT ATL STL DEN DFW DCA
Minimum Spanning Tree (MST) Spanning subgraph Subgraph w/ all vertices Spanning tree Combines spanning subgraph + tree ORD PIT ATL STL DEN DFW DCA
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
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 e f e f
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
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
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
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
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
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
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO 187
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
Kruskal Example BOS PVD JFK ORD BWI 184 MIA DFW LAX SFO
For Next Lecture