Regarding disjoint-set data structures, what is the point of doing union by rank? I get the purpose of "weighted union" when implementing the data structures as linked lists (less objects to update per union).
However, when union by rank is related to tree implementation. Here, you update the parents of roots when uniting two trees. So if x
and y
were trees and you called union(x,y)
, the parent of the root of the tree containing x
would be linked to the root of the tree containing y
. This takes constant time - so what is there to optimize? Like why would union by rank give any better results if you only have to update a pointer?