UnionFind
UnionFind, also known as Disjoint Set Union (DSU), is a data structure that maintains a partition of a set into disjoint subsets. It supports two primary operations: find(x), which returns the representative or root of the set containing x, and union(x, y), which merges the sets containing x and y into a single set. A common auxiliary function is connected(x, y), which tests whether x and y belong to the same set. The structure represents each set as a tree, with each node pointing to a parent and the root serving as the set representative.
Typical implementation uses two arrays: parent and rank (or size). Initially, each element is its own parent,
Time complexity is nearly linear in practice. Each operation runs in amortized inverse Ackermann time, α(n),
Limitations include difficulty supporting deletions; dynamic connectivity with removals requires more advanced variants. UnionFind remains a