What is the order in this Union by Rank diagram?
-
04-10-2020 - |
Solution
The rule for union by rank is to attach the smallest tree to the root of the largest tree.
At the first step A
is united to D
(this is just an example I guess - you could do any other way), so after union(A, D)
you can have either A_0 -> D_1
or D_O -> A_1
since the 2 singleton trees have the same rank you pick one at random, in this case D
, to be the root.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow