sir how to implement union by rank then?
Implementation issue
In this approach we use the size of the trees as rank,
we attach the tree with the lower rank to the one with the bigger rank.
you can have a look at this link for the implementation, feel free to ask if you have any doubts left.
https://cp-algorithms.com/data_structures/disjoint_set_union.html#toc-tgt-3