Guest User
Using app without sign in

Practice book
Graph Theory Through Problems300 Exercises with Hints, Worked Algorithms and Complete Solutions
By Mohammed Islam Hadjoudj
Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
The lightest cut, with no source or sink
Global minimum cut of an undirected weighted graph: maximum adjacency phases, then merge the last two vertices
Select an algorithm and generate steps to begin visualization
The Stoer-Wagner algorithm finds a minimum cut of an undirected weighted graph: the set of edges with the smallest total weight whose removal splits the graph into two parts. Unlike a minimum s-t cut, no source or sink is given, so it measures how strongly the graph as a whole holds together. Mechthild Stoer and Frank Wagner published it in 1997 as a simple deterministic alternative to running maximum flow many times.
The algorithm runs in phases. A phase starts a set A with one vertex and repeatedly adds the vertex most tightly connected to A, the one whose edges into A weigh the most. The last vertex added, t, is cut off from everything else; this cut of the phase is a candidate. A key lemma says that no cut separating t from the vertex added just before it, s, is lighter, so any lighter cut keeps s and t together, and they can be merged into one vertex. After n - 1 phases only one vertex is left, and the lightest cut of a phase is the minimum cut. With a priority queue the running time is O(VE + V² log V).
Global minimum cuts measure the edge connectivity of networks, find the weakest point of communication and power grids, split graphs into clusters for image segmentation and community detection, and guide circuit partitioning in chip design. In algorithms courses Stoer-Wagner is the classic deterministic minimum cut algorithm, next to Karger's randomized contraction algorithm.
Stoer-Wagner finds a global minimum cut of a weighted undirected graph without any flow computation. It runs V - 1 phases, each of which grows a set by the most tightly connected vertex and then merges the last two vertices added.
StoerWagner(graph):
best = infinity
while graph has more than one vertex:
A = {a} // any fixed start vertex
while A is not all vertices:
add the vertex v outside A with the largest w(A, v)
s, t = the last two vertices added
cut = w(t, everything else) // cut of the phase
if cut < best: best = cut, record the vertices merged into t
merge t into s, adding parallel edge weights
return bestThe correctness rests on one lemma: the cut of the phase, which separates the last vertex t from everything else, is a minimum cut between s and t. So either the global minimum cut separates s and t, and this phase found it, or it puts them on the same side, and merging them loses nothing. After V - 1 phases every possibility has been covered.
Run Stoer-Wagner on the example this page loads, the eight-vertex graph used in the original 1997 paper by Stoer and Wagner. Every phase starts from vertex 1.
Example graph: Undirected weighted edges 1-2 (2), 1-5 (3), 2-3 (3), 2-5 (2), 2-6 (2), 3-4 (4), 3-7 (2), 4-7 (2), 4-8 (2), 5-6 (3), 6-7 (1) and 7-8 (3).
The minimum cut weighs 4 and separates {1, 2, 5, 6} from {3, 4, 7, 8}, cutting only the edges 2-3 and 6-7. Note that cutting off a single vertex is not the answer: the lightest ones, 1 and 8, weigh 5 each. Note also that no source or sink was ever chosen: the algorithm compares all possible bipartitions implicitly through the merges.
Time: O(VE + V^2 log V) · Space: O(V + E)
There are V - 1 phases, because each merges two vertices. One phase is structurally the same as Prim's algorithm: a priority queue keyed by the connection weight to A, with one extract-max per vertex and one key increase per edge. With a Fibonacci heap that is O(E + V log V) per phase, so O(VE + V^2 log V) overall. With an adjacency matrix and a linear scan for the maximum, a phase costs O(V^2) and the whole algorithm O(V^3), which is simpler and perfectly adequate for dense graphs of a few hundred vertices.
Choose by whether you want the cut between two given vertices or the weakest cut anywhere in the graph.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Max-flow min-cut | You need the minimum cut between two specific vertices s and t, or the graph is directed. | O(V^2 E) with Dinic |
| V - 1 max-flow runs | A naive global cut: fix s and try every t. Correct but much slower than Stoer-Wagner. | V - 1 max flows |
| Karger-Stein | Very large graphs where a randomised answer that is correct with high probability is acceptable. | O(V^2 log^3 V) |
| Gomory-Hu tree | You need minimum cuts between all pairs of vertices, not just the global one. | V - 1 max flows |
Read the full article: Minimum Cut in Graphs: s-t Cuts, Global Cuts and Code
Read the full article: Max-Flow Min-Cut Theorem & Network Flow
Related algorithms: Minimum Cut, Maximum Flow, Dinic's Algorithm, Bridge Finding