Kruskal's code rank compression

the instructor refers here for rank compression videos but the same is not provided please provide explanation of that and cpp code for the same

@Divya_321 This is the implementation of rank comperession in disjoint sets Union .
Here rank denotes the size of the components.

void union_sets(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (rank[a] < rank[b])
swap(a, b);
parent[b] = a;
if (rank[a] == rank[b])
rank[a]++;
}
}

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.