Mental Model
Path compression flattens the structure of the union find tree by making nodes point directly to the root, speeding up future searches.
Analogy: Imagine a family tree where each person points to their parent. Path compression is like updating everyone in a branch to point directly to the oldest ancestor, so you can find the root ancestor faster next time.
Before path compression: 1 -> 2 -> 3 -> 4 -> null After path compression: 1 -> 4 2 -> 4 3 -> 4 4 -> null