Simulation: Union (U) and Find (F)
Simulation: Union (U) and Find (F)
Consider a
i
SIMULATION
Start with six disjoint subsets. 1 2 3 4 5 6
-1
-1
-1
-1
-1
-1
U(1,3)----1 and 3 are in sets 1 and 3, and both are singleton sets, so by the weighting rule either can be made the parent of the other. 3 4 5 6
-1 1
-2
-1
-1
-1
U(4,5)---4 and 5 are in singleton sets 4 and 5. So we can make either of them the parent of the other. 2 3 5 6
-1 1
-2
-2
-1
F(2) gives 2 in set number two, no collapsing is involved. U(1,2)--- 1 is in set no. 3 and 2 is in set no. 2, with 2 and 1 elements respectively. By the weighting rule 3 is made the parent of 2. 3 5 6
-3 1
-2
-1
U(1,6)---1 is in set no. 3 which has a cardinality of 3, and 6 is in set 6 with a cardinality of 1. The former is made the parent of the latter.
3 5 -4 1 6 4 -2
F(5) --- 5 is in set no. 5 and no collapsing is involved. U(1,4)---1 is in set no. 3 which has a cardinality of 4, and 4 is in set 5 which has a cardinality of 2. By the weighting rule 3 becomes the parent of 5.
3 6
-6 1
Note:- If we now have F(4) then the collapsing rule applies to the above.