Disjoint Set Union
Maintain dynamic connectivity with parent forests
Represent each component by a root
Disjoint set union (DSU), also called union-find, partitions elements into non-overlapping sets. find(x) follows parent links to a representative root, and union(a, b) connects two roots when their sets differ.
Current components: 8
Choose two elements to unite, find a root, or test connectivity. Each starts alone.
Flatten paths as they are discovered
Path compression makes every node seen by find point directly toward the root. Union by rank or size attaches the smaller tree below the larger one. Together, these rules make a long sequence of operations take almost constant amortized time, O(alpha(n)) per operation.
DSU is the cycle detector inside Kruskal's minimum spanning tree and is widely used for offline connectivity problems.