Which root goes on top?
transcript
Two groups merge. One root must go on top. Union-find decides with a simple rule. Does the choice matter? Take six accounts and five links, in a line.
Say the first root always goes under the second. Five links build one long chain. Each link adds one more step to the chain. A find from zero walks five steps. Imagine a million accounts in a chain like that.
Now the smaller tree's root goes under the larger. The same five links build a star. Zero stays the root of all six accounts. Every account is one step from the root.
An account gets deeper only in the smaller tree. Then its tree at least doubles in size. A tree cannot double more than log base two of n times. For a million accounts, that is at most nineteen steps. So no tree is taller than that.
Same links, same groups. A much shorter tree. Short trees mean fast finds. Full breakdown in the lecture.