Union-Find & Spanning Trees
Track dynamic connectivity with union-find and build minimum spanning trees with Kruskal's and Prim's algorithms.
3 objectives 6 steps about 115 min
Check what you know
The lessons are coming later. The knowledge check is ready now.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Implement union-find with path compression and union by size, and explain its near-constant amortized cost per operation.
- Apply union-find to connectivity problems: counting components as edges arrive, finding a redundant edge, and grouping equivalent items.
- Compute a minimum spanning tree with Kruskal's algorithm (sort plus union-find) and Prim's algorithm (heap), and justify both with the cut property.
Lesson plan
6 steps, about 115 min · 0 of 5 lessons available so far
- Disjoint Sets and Representatives Concept · 15 min · coming later
- Lab: Path Compression and Union by Size Lab · 25 min · coming later
- Connectivity Questions Answered Online Worked example · 20 min · coming later
- The Cut Property and Kruskal's Algorithm Worked example · 25 min · coming later
- Prim's Algorithm and When to Prefer It Worked example · 15 min · coming later
- Check: Connectivity and MST Problems Knowledge check · 6 questions
Practise it
Implement UnionFind and use it to merge accounts that share an email and to find a redundant connection; then compute the minimum spanning tree of a 5,000-edge cable-layout graph with both Kruskal and Prim and confirm the total weights match.
References
Hard prerequisites
Unlocks
Nothing depends on this skill yet.
On these roadmaps
Progress and evidence for this skill are shared across all of them.