What is 'Path Compression' and 'Union by Rank'?
What is 'Path Compression' and 'Union by Rank'?
Approach: Describe the two key optimizations for Union-Find.
Path compression flattens the tree during Find. Union by rank attaches the shorter tree to the root of the taller tree. Together, they make operations almost constant time.
Follow-up: What is the resulting complexity per operation?
Key concepts: flattening, shorter trees, inverse ackermann.