Kruskal
Kruskal
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
this.src = src;
this.dest = dest;
this.weight = weight;
this.parent = parent;
this.rank = rank;
}
// Starting point of program execution
/*****************************************
10
0--------1
|- |
6| 5- |15
| -|
2--------3
*****************************************/
int V = 4;
new Edge(2, 3, 4)
));
graphEdges.sort(new Comparator<Edge>() {
@Override
});
kruskals(V, graphEdges);
}
int j = 0;
int noOfEdges = 0;
if (x != y) {
results[noOfEdges] = nextEdge;
union(subsets, x, y);
noOfEdges++;
j++;
System.out.println("-----------------------------------------------");
int minCost = 0;
minCost += results[i].weight;
System.out.println("-----------------------------------------------");
subsets[rootY].parent = rootX;
subsets[rootX].parent = rootY;
} else {
subsets[rootY].parent = rootX;
subsets[rootX].rank++;
}
if (subsets[i].parent == i)
return subsets[i].parent;
return subsets[i].parent;