Progb 8
Progb 8
Kruskal’s algorithm
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;
}
public static void main(String[] args)
int V=4;
graphEdges.sort(new Comparator<Edge>()
});
kruskals(V, graphEdges);
int j = 0;
int noOfEdges = 0;
if (x != y)
union(subsets, x, y);
noOfEdges++;
j++;
int minCost = 0;
System.out.println(results[i].src+"--"+results[i].dest+" == "+results[i].weight);
minCost += results[i].weight;
else
subsets [rootX].rank++;
if (subsets[i].parent == i)
return subsets[i].parent;
return subsets[i].parent;
}
OUTPUT:
2--3 == 4
0--3 == 5
0--1 == 10