Clever Data Structure

Can represent the set of groups with a new DAG with one node per vertex from the original weighted graph. Each node points to another vertex in its set, with the ``root'' being the set's label.

Now, to join u and v, we simply make the root of the smaller set (say v) point to u.

Checking to see if u and v are connected amounts to finding the roots of each DAG to see if they are the same.

As an additional heuristic, when we follow a chain to a root, we do path compression: take a second pass through the list and make all the nodes point directly at the root, resulting in a faster test next time. (Remind you of anything?)


next up previous
Next: Culture Up: FAST UNION-FIND Previous: Quick Aside