Weighted Quick Union
Weighted Quick Union
Keep track of size of each tree (number of objects).
Balance by linking root of smaller tree to root of larger tree.


Data structure Same as quick-union, but maintain extra array sz[i] to count number of objects in the tree rooted at i.
Java Implementation
Analysis
Find: takes time proportional to depth of
pandq.Union: takes constant time, given roots.
Depth of any node
xis at mostlog(N).
Last updated
Was this helpful?