MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / union

Method union

CountTheNumberOfCompleteComponents.java:50–64  ·  view source on GitHub ↗
(int node1, int node2)

Source from the content-addressed store, hash-verified

48 }
49
50 void union(int node1, int node2) {
51 int rootParent1 = find(node1);
52 int rootParent2 = find(node2);
53
54 if (rootParent1 == rootParent2) {
55 return;
56 }
57 if (size[rootParent1] > size[rootParent2]) {
58 parent[rootParent2] = rootParent1;
59 size[rootParent1] += size[rootParent2];
60 } else {
61 parent[rootParent1] = rootParent2;
62 size[rootParent2] += size[rootParent1];
63 }
64 }
65 }
66}

Callers 1

Calls 1

findMethod · 0.95

Tested by

no test coverage detected