AlgoViz

Union-find

medium 20 min

Union-find, also called a disjoint set union (DSU), keeps elements split into non-overlapping groups.

Chapter mnemonic

Two Union-Find optimizations

Small hill joins tall hill. Trail signs point to the summit.

Which optimization changes signposts along an existing path?

Path compression redirects visited nodes toward the root. Union by rank guides the merge of two trees.