Mental Model
Union Find keeps track of groups of connected items by linking them under a single leader. It helps quickly find if two items belong to the same group.
Analogy: Imagine a classroom where students form friend groups. Each group has a leader. If two students are friends, they share the same leader. Union Find helps find the leader of any student and join two groups by choosing one leader.
0 1 2 3 4 5 6 7 8 9 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ Each number is alone, leader points to itself: 0 -> 0 1 -> 1 2 -> 2 3 -> 3 4 -> 4 5 -> 5 6 -> 6 7 -> 7 8 -> 8 9 -> 9