23. MST-outside

# Merge closest clusters and their msts a priority

• Notes
• 17

This preview shows pages 5–11. Sign up to view the full content.

Merge “closest” clusters  and their MSTs A priority queue stores the  edges outside clusters Key: weight Element: edge At the end of the algorithm One cluster and one MST Minimum Spanning Trees 5 Algorithm KruskalMST ( G ) for each vertex v in G do Create a cluster consisting of v let Q be a priority queue. Insert all edges into Q T { T is the union of the MSTs of the clusters} while T has fewer than n - 1 edges do e Q.removeMin () .getValue () [ u , v ] G.endVertices ( e ) A getCluster ( u ) B getCluster ( v ) if A B then Add edge e to T mergeClusters ( A, B ) return T

This preview has intentionally blurred sections. Sign up to view the full version.

©  2010 Goodrich, Tamassia Campus Tour 6 Example B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9
©  2010 Goodrich, Tamassia Campus Tour 7 Example (contd.) four steps two steps B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9 B G C A F D 4 1 3 5 10 2 8 7 6 E H 11 9

This preview has intentionally blurred sections. Sign up to view the full version.

©  2010 Goodrich, Tamassia Data Structure for Kruskal’s  Algorithm The algorithm maintains a forest of trees A priority queue extracts the edges by increasing  weight An edge is accepted it if connects distinct trees We need a data structure that maintains a  partition , i.e., a collection of disjoint sets, with  operations: makeSet (u): create a set consisting of u find (u): return the set storing u union (A, B): replace sets A and B with their union Minimum Spanning Trees 8
©  2010 Goodrich, Tamassia Minimum Spanning Trees 9 Recall of List-based  Partition Each set is stored in a sequence Each element has a reference back to the set operation  find (u) takes O(1) time, and returns the set of  which u is a member. in operation  union (A,B), we move the elements of the  smaller set to the sequence of the larger set and update  their references the time for operation  union (A,B) is min(|A|, |B|) Whenever an element is processed, it goes into a  set of size at least double, hence each element is  processed at most log n times

This preview has intentionally blurred sections. Sign up to view the full version.

©  2010 Goodrich, Tamassia Partition-Based Implementation Partition-based  version of
This is the end of the preview. Sign up to access the rest of the document.
• Fall '09
• Vertex, Tamassia, Minimum Spanning Trees

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern