What is a Disjoint Set Union (DSU) or Union-Find?

What is a Disjoint Set Union (DSU) or Union-Find?

Approach: Describe a structure for tracking elements partitioned into disjoint subsets.

A data structure that stores a collection of disjoint sets. It supports two operations: Find (determine which set an element belongs to) and Union (join two sets into one). Optimization with path compression yields near-constant time operations.

Follow-up: What is the time complexity in terms of the inverse Ackermann function?

Key concepts: path compression, union by rank, connectivity.