Union by Rank and Components
Keep trees flat and count groups.
Union Can Be Lazy
Plain union just hangs one root under another. Done carelessly, it can build a tall, slow tree, so we need a smarter way to merge roots.
The Big Idea
Union by rank always attaches the shorter tree under the taller one. Keeping trees shallow makes every later find faster. 📏
All lessons in this course
- DSU with Path Compression
- Union by Rank and Components
- Kruskal's Minimum Spanning Tree
- Prim's MST with a Heap