Connect components with disjoint-set union
8 steps · about 2 h 55 min · Intermediate
- Learn make, find and union (guide, CP-Algorithms, 25 min)
Introduces the three operations and improves the basic forest one optimization at a time.
- Frame the dynamic-connectivity problem (reference, Princeton University, 20 min)
Starts from a concrete connectivity API and compares several implementations by measured cost.
- Place union-find among graph structures (guide, Open Data Structures, 15 min)
Connects the structure to component tracking and gives exercises that expose its limits.
- Visualize forest merging (interactive, University of San Francisco, 20 min)
Makes parent links, ranks and compressed paths visible after every operation.
- Read a compact weighted implementation (guide, Princeton University, 20 min)
A short reference implementation makes the parent and size invariants easy to annotate and test.
- Use components while building an MST (guide, Princeton University, 25 min)
Kruskal's algorithm gives union-find a real job: reject edges whose endpoints are already connected.
- Find the edge that closes a cycle (interactive, GeeksforGeeks, 25 min)
Applies find-before-union to detect exactly when an undirected graph stops being a forest.
- Count final connected components (interactive, GeeksforGeeks, 25 min)
Checks initialization, repeated unions and correct counting of distinct roots on a small graph.