Find the boss, leave a shortcut
transcript
Every account points to a parent. Follow the parents, and you reach a root. The root is the boss of the whole group. A group is a tree of parent pointers. Let us find the boss of account three.
We start at three, and go up. Account three points to two. Two points to zero. Zero points to itself. Zero is the root. That walk took two steps.
Now point three straight at zero. Every account on the walk gets a shortcut. Zero is still the root of the group. The next find from three takes one step. The groups did not change. Only the shape did.
A walk of two steps costs two steps. But it leaves shortcuts behind it. Later finds from those accounts take one step. One slow find does not make the next one slow. Spread over many finds, the cost of each stays small.
This is path compression. It never changes who is in which group. Full breakdown in the lecture.