Idea: union-find via "lazy ids" [00P6]

It turns out that the first idea above (having a dictionary mapping every item to an id for its set) is a good starting place. \mathsf {Union} took too long since we had to update every single item in a set to reference a new set. But what if we didn't have to update all of them?

We can do this if we allow ourselves a bit of indirection: rather than having every item reference its set, we can have every item either reference its set or another item in the same set. Imagine arranging all the items in a set into a tree: the item at the root is the only one that directly references the identity of the set (in fact, we can use the root item itself as the "name" of the set, like naming a group after its leader); every other item references some other item in the set, but ultimately if we keep following references we always end up at the root. Now, in order to change the identity of a set, we only need to update the root item itself; all the other items just "come along for the ride".