Question: In practice, union - by - height is not commonly used, as the height of a node must be recalculated every time we perform path
In practice, unionbyheight is not commonly used, as the height of a node must be recalculated every time we perform path compression. Instead, we usually opt for unionbyrank, where each node stores its rank, an upper bound for its height. When a node is initialized, its rank is set to zero, and when a union operation is performed on the sets with representatives x and y we follow this procedure:
If xrank yrank, then x becomes the parent of y and vice versa and the ranks of x and y do not change.
If xrank yrank, then either one can become the parent of the other, but the rank of the chosen parent increases by one.
The rank is otherwise not recalculated, even during path compression.
Prove that every node has rank lfloorlog nrfloor at most.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
