I'm a beginner and I am trying to find the minimum cut of a graph using Kruskal's algorithm in Java.
I have gotten to where I can read the input and create vertexCount^2 number of MST's with random weights for the edges. All I have left to do is figure out from my MST how many cuts are required to separate S and V-S. This will allow me to choose the minimum out of the vertexCount^2 number of choices.
I think I understand correctly that I am supposed to ignore the last edge of the MST to get S and V-S. But I'm lost on how to figure out how many edges are connecting S and V-S.
So my question is: 1) Is vertexCount^2 random MST's enough to be confident that it will contain the minimum-cut? 2) How can I find how many edges are connecting S and V-S?
PS. This is a snippet form my code:
// create weighted edge graph from input.txt
int vertexCount, edgeCount;
Edge edgeTemp;
vertexCount = s.nextInt();
edgeCount = s.nextInt();
EdgeWeightedGraph G = new EdgeWeightedGraph(vertexCount, edgeCount);
for (int j = 0; j < edgeCount; j++) {
edgeTemp = new Edge(s.nextInt(), s.nextInt(), new Random().nextInt(edgeCount));
G.addEdge(edgeTemp);
}
// create kruskal's mst from graph G
for (int j = 0; j < vertexCount*vertexCount; j++) {
KruskalMST mst = new KruskalMST(G);
for (Edge e : mst.edges()) {
System.out.println(e);
}
System.out.println(NEWLINE);
if (j != vertexCount*vertexCount - 2)
G.randomizeWeight(edgeCount);
}
PSS. In case this is relevant, I looked at the code from http://algs4.cs.princeton.edu/43mst/ when writing my code.