Guild Union Find
Players keep forming guilds, and the game server must instantly answer: "Are these two players on the same team?" Build a tracker that merges teams fast and never walks a long chain twice.
๐ง Before we start
Dynamic Route saved answers so repeated work disappeared. Today's union-find (disjoint sets) keeps groups that never overlap. Every player points to a parent, and the team leader is the player who points to themself.
Build the tracker strategy
Arrange the four visual cards in the order a union-find tracker uses them. Everyone begins alone.
Find the leader, then merge
Each handshake joins two players. First find a player's leader by following parent links, then the tracker merges the two teams.
Merge smart: small under big
Ada's team has 4 players. Eli's team has 2. Their leaders must be joined. Which merge keeps future lookups shortest?
Compress the long chain
Mia's leader lookup walks four parent links. After you find the leader, tap every walked player to point straight at the leader.
๐ What you learned
- Union-find stores non-overlapping groups with a parent link for each item.
- A leader (root) is the item whose parent is itself.
- Find follows parents until it reaches the leader; two items are in the same group when their leaders match.
- Union merges two groups by linking one leader to the other.
- Union by size attaches the smaller group under the larger so chains stay short.
- Path compression rewires visited items straight to the leader, making repeat lookups fast.