learngraphtheory.org

Guest User

Using app without sign in

Cover of the book Graph Theory Through Problems

Practice book

Graph Theory Through Problems

300 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.

Available inKindlePaperback

13 chapters

Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on Amazon
Algorithm Selection

Select an algorithm and generate steps to begin visualization

Stoer-Wagner Calculator

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

Time: O(VE + V² log V)
Space: O(V + E)
Use Case: Network reliability, graph clustering, circuit partitioning
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Stoer-Wagner Min Cut

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.

How it works

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).

Applications

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.

Pseudocode

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 best

The 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.

Worked example, step by step

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).

  1. Phase 1. From {1} the most tightly connected vertex is 5 (weight 3). Then 2 joins with 4, 6 with 5, 3 with 3, 4 with 4 and 7 with 5. The last vertex is 8, and its edges 4-8 and 7-8 give a cut of the phase of weight 5. Vertices 7 and 8 are merged.
  2. Phases 2 and 3. The order 1, 5, 2, 6, 3, 4 repeats, so the merged vertex {7, 8} is last, with a cut of weight 7, and is merged with 4. In phase 3 the group {4, 7, 8} is last, again with cut weight 7, and is merged with 3.
  3. Phase 4. Now the order is 1, 5, 2, 6, and the last group is {3, 4, 7, 8}. It is attached to the rest only by 2-3 (3) and 6-7 (1), so the cut of the phase weighs 4, the best so far.
  4. Phases 5 to 7. The remaining phases produce cuts of weight 8, 7 and 5 as the groups keep merging. None beats 4.

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.

Complexity, and where it comes from

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.

When to use Stoer-Wagner Min Cut, and when not to

Choose by whether you want the cut between two given vertices or the weakest cut anywhere in the graph.

AlternativePrefer it whenCost
Max-flow min-cutYou 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 runsA naive global cut: fix s and try every t. Correct but much slower than Stoer-Wagner.V - 1 max flows
Karger-SteinVery large graphs where a randomised answer that is correct with high probability is acceptable.O(V^2 log^3 V)
Gomory-Hu treeYou need minimum cuts between all pairs of vertices, not just the global one.V - 1 max flows

Common pitfalls

  • Using it for an s-t cut. Stoer-Wagner finds the lightest cut anywhere. If you need s and t on opposite sides, the global minimum may put them together. Use max flow for that question.
  • Negative or directed weights. The lemma requires nonnegative weights on undirected edges. With negative weights or directed edges the cut of the phase is no longer a minimum s-t cut and the result can be wrong.
  • Losing track of the merged vertices. The minimum value is easy to record, but reporting which vertices are on each side needs the list of original vertices merged into each super-vertex. Keep it from the start.
  • Disconnected input. If the graph is not connected, the minimum cut is 0. Check connectivity first, both to answer immediately and to avoid phases that add vertices with connection weight 0 in arbitrary order.

Frequently asked questions

What does the Stoer-Wagner algorithm compute?
The global minimum cut of an undirected graph with nonnegative edge weights: the partition of the vertices into two nonempty sides that minimises the total weight of edges between them. It needs no source and sink.
What is a minimum cut phase?
Starting from one vertex, the phase repeatedly adds the outside vertex with the largest total edge weight to the growing set. The weight between the last vertex added and all the others is the cut of the phase, and the last two vertices are then merged.
What is the time complexity of Stoer-Wagner?
O(VE + V^2 log V) with a Fibonacci heap, or O(V^3) with an adjacency matrix. There are V - 1 phases and each is a Prim-like scan over the graph.
How is Stoer-Wagner different from max-flow min-cut?
Max-flow min-cut gives the cheapest cut separating two chosen vertices. Stoer-Wagner gives the cheapest cut overall. Computing the global cut with max flow requires V - 1 separate flow computations, which Stoer-Wagner avoids entirely.
Where are global minimum cuts used?
In network reliability, where the minimum cut is the weakest set of links whose failure splits the network, in image segmentation and clustering, where weak cuts separate natural groups, and in VLSI design, to partition circuits with few connections between the parts.

Related algorithms: Minimum Cut, Maximum Flow, Dinic's Algorithm, Bridge Finding

Interactive Controls

Zoom Controls

41%
Nodes: 8
Edges: 12