Union-find, also called a disjoint set, keeps elements in groups that never overlap. Find(x) returns the representative of x’s group and Union(a, b) merges two groups. With path compression and union by size, a sequence of operations is almost linear in total, according to the literature.