Okay so here’s my algorithm for finding a Cut in a graph (I’m not talking about a min cut here)
Say we’re given an adjacency list of a non-directed graph.
- Choose any vertice on the graph (let this be denoted by pivot)
- Choose any other vertice on the graph (randomly). (denote this by x)
- If the two vertices have an edge between them, then remove that edge from the graph. And dump all the vertices that x is connected to, onto pivot. (if not then go back to Step 2.
- If any other vertices were connected to x, then change the adjacency list so that now x is replaced by pivot. Ie they’re connected to Pivot.
- If number of vertices is greater than 2 (go back to step 2)
- If equal to 2. Just count number of vertices present in adjacency list of either of the 2 points. This will give the cut
My question is, is this algorithm correct?
That is a nice explanation of Krager’s Min-Cut Algorithm for undirected graphs.
I think there might one detail you missed. Or perhaps I just mis-read your description.
You want to remove all self-loops.
For instance, after you remove a vertex and run through your algorithm, Vertex A may now have an edge that goes from Vertex A to Vertex A. This is called a self-loop. And they are generated frequently in process of contracting two vertices. As a first step, you can simply check the whole graph for self-loops, though there are some more sophisticated approaches.
Does that make sense?