Can someone check with me if I use the rule correctly in the last step (7)?
UPDATE:
The numbers inside parentheses are the number of elements (weight (?)) Of each set participating in the Union. Uppercase letters are set names.
As I understand it: we use the number of elements as our rank? This is confusing; everyone uses different terms for the same material.
We have Unions:
Step 7 (and others) looks correct, but step 6 does not work.
In step 6-4, there should be a root, as this is a larger tree.
void combine(int x,int y) { int xroot=find(x),yroot=find(y); if(rank[xroot]<rank[yroot]) parent[xroot]=yroot; else if(rank[xroot]>rank[yroot]) parent[yroot]=xroot; else {///rank of both is equal.. parent[yroot]=xroot; rank[xroot]++; } }
, size of set, , 6 .
size of set
6
size?, , update .
size
update
CLRS ( ).
, !