CS 411 Fall 2025 > Outline for November 3, 2025
CS 411 Fall 2025
Outline
for November 3, 2025
Outline
Spanning Trees II: Kruskal’s Algorithm & Union-Find [L 9.2]
- Kruskal’s Algorithm: Idea
- Once again, we solve the Minimum Spanning Tree Problem.
- Greedy algorithmic idea #2 (Kruskal’s Algorithm). Repeat: Add to a collection of edges the least-weight edge whose addition will not form a cycle.
- Prim’s Algorithm keeps track of an expanding tree that eventually reaches all vertices. Kruskal’s Algorithm begins with all vertices and adds edges, maintaining an acyclic graph, until a tree is formed.
- Implementations are very different. For Kruskal’s Algorithm, we need a fast way to determine whether the addition of an edge will create a cycle.
- Union-Find
- Idea: “blobs” (sets), each containing one or more points. We can determine whether two points are in the same blob, and we can merge blobs.
- ADT: Union-Find.
- Data: A set of points.
- Operations:
- MakeSet: Create a new single-point set.
- Find: Given a point, determine which set it lies in.
- Union: Given two points, merge their sets.
- Other names: Disjoint-Set, Find-Merge, Merge-Find.
- For the Find operation, we designate, for each set, a representative point. Find returns the representative for the given point’s set. Representatives stay consistent until the next Union operation. So to determine whether two points lie in the same set, do a Find on each, and compare the results.
- Two implementations
- Quick Find. Keep an array of representatives for each point. Find does a look-up. Union does whatever it needs to, to update the array. Each set probably stored as linked list of points.
- Quick Union, a.k.a. Disjoint-Set Forest (much more common). Sets stored as rooted trees. Root is representative. Each point has a pointer to its parent, or to itself if it is the root. To Find, follow pointers to the root. To Union, do a Find on each given point; point the root of one tree at the root of the other.
Spanning Trees II: Kruskal’s Algorithm & Union-Find will be continued next time.