lecture 35: spanning trees

Click here to load reader

Post on 24-Feb-2016

39 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Splay Trees

Lecture 35:Spanning TreesCSC 213 Large Scale Programming#Minimum Spanning Tree (MST)Spanning subgraphSubgraph w/ all verticesSpanning treeCombinesspanning subgraph + treeORDPITATLSTLDENDFWDCA10198632574#Minimum Spanning Tree (MST)Spanning subgraphSubgraph w/ all verticesSpanning treeCombinesspanning subgraph + treeMSTSpanning tree which minimizes sum of edge weightsORDPITATLSTLDENDFWDCA10198632574#No Cycles in MSTEdge in MST cheaper than one making cycleAssume there exists an edge e not in MSTCycle, C, occurs after adding e to min. spanning treeAssume that f in C heavier than eShrink MST using e and dropping f from C842367798ef842367798ef#Partition PropertyGiven partitioning of vertices in a graphRequired that each vertex in exactly 1 partitionUse smallest edge to connect each of theTo complete following MST, can use either f or e742857398#Kruskals AlgorithmSimilar to Prim-Jarnik, including finding MSTAlso like Prim-Jarnik, adds edges greedilyBut Kruskal processes Edges using PriorityQueueCheck if Edge makes cycle before adding to MSTNo cycles in an MST, so add Edge if no cycle occursDetecting cycles hard, however#Kruskals AlgorithmSimilar to Prim-Jarnik, including finding MSTAlso like Prim-Jarnik, adds edges greedilyBut Kruskal processes Edges using PriorityQueueCheck if Edge makes cycle before adding to MSTNo cycles in an MST, so add Edge if no cycle occursDetecting cycles hard, however

#Kruskals AlgorithmSimilar to Prim-Jarnik, including finding MSTAlso like Prim-Jarnik, adds edges greedilyBut Kruskal processes Edges using PriorityQueueCheck if Edge makes cycle before adding to MSTNo cycles in an MST, so add Edge if no cycle occursDetecting cycles hard, however

#Structure for Kruskals AlgorithmKruskals needs to maintain collection of treesAccept Edge connecting 2 trees & reject it otherwiseData structure named Partition relied uponStore disjoint Set instances within a Partition For Kruskals, each Set holds tree from graphMethods supporting Sets defined by Partition find(u): find and returns Set containing uunion(p,r): replace p & r with their unionmakeSet(u): creates Set for u & adds to Partition #Kruskals AlgorithmAlgorithm 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 Example867270412588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO187#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#Kruskal Example867270418712588491447401391946109011212342184662180214641235337BOSPVDJFKORDBWI184MIADFWLAXSFO#For Next LectureWeekly assignment available on AngelDue at special time: before next Mondays quizProgramming assignment #3 designs due today

Graph Quiz will be on MondayStarted before test, so could include implementationsBring notes, templates, & anything else you wantWeekly assignment question review highly encouraged