Union-Find
Union-Find maintains a collection of disjoint sets and supports finding the representative of a set and merging two sets. Path compression makes future find operations faster by attaching visited nodes directly to the root. Union by rank or size attaches the smaller tree under the larger one, keeping the structure shallow.
find identifies the set representative.
union merges two sets.
Path compression flattens find paths.
Union by rank or size controls tree height.
Amortized complexity is O(alpha(n)), effectively constant for practical sizes.