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

Method union

MinimumCostWalkInWeightedGraph.java:18–32  ·  view source on GitHub ↗
(int node1, int node2)

Source from the content-addressed store, hash-verified

16 return parent[node];
17 }
18 public void union(int node1, int node2){
19 int rootParent1 = find(node1);
20 int rootParent2 = find(node2);
21 if(rootParent1 == rootParent2){
22 return;
23 }
24 if(rank[rootParent1] < rank[rootParent2]){
25 parent[rootParent1] = rootParent2;
26 }else if(rank[rootParent2] < rank[rootParent1]){
27 parent[rootParent2] = rootParent1;
28 }else{
29 parent[rootParent2] = rootParent1;
30 rank[rootParent1]++;
31 }
32 }
33}
34
35class Solution {

Callers 1

minimumCostMethod · 0.95

Calls 1

findMethod · 0.95

Tested by

no test coverage detected