Union-Find — Two Optimizations Make It Practically Constant
Union-Find gives each group a root representative and decides whether two elements share a group. The unoptimized version stretches find to O(N) on chain trees; path compression and union by rank make it practically constant.