How Stoer-Wagner finds a global min-cut

Short answer: Stoer-Wagner computes a global minimum cut of an undirected weighted graph deterministically. Each phase grows a set like Prim, always adding the vertex most tightly connected to the set. The cut that separates the last vertex of the phase from the rest is a candidate. The phase then contracts its last two vertices and repeats. The lightest candidate over all phases is a global min-cut. A binary heap implements the growth in O(VE + V² log V) time, and a simple array scan is O(V³).


What the problem actually asks

A global min-cut partitions the vertices into two nonempty sides so that the total weight of edges across the partition is minimum. No source or sink is given. An s-t flow answers the question only after every pair is tried, which is wasteful, because a global min-cut is an s-t min-cut for the two vertices that end up on opposite sides of it.

Stoer-Wagner manufactures those two vertices. In a phase, the last vertex added is as tightly tied to the grown set as possible, and the edge weight between the final vertex and the set is the min-cut of a particular pair. Contracting that pair preserves some global min-cut of the original graph.


What the algorithm guarantees

The minimum of the phase cuts equals the global minimum cut. There are V−1 phases, because each phase contracts two vertices into one. With a heap, each phase is a Prim-like growth, and the total is O(VE + V² log V). The array implementation, which scans for the tightest vertex each time, is O(V³) and is the one to write first. Extra memory is the contraction, which can be a weight matrix that adds parallel edges by summing weights.

The algorithm is undirected. Directed cuts are s-t flow problems. Negative edge weights are outside the usual statement, because tightness is a sum of weights and a negative edge makes “most tightly connected” the wrong greedy choice for a cut. Zero-weight edges are fine.


The working steps

  1. Represent the undirected graph so parallel edges combine by adding weights. Start with the original vertices as the supernodes.
  2. In a phase, grow a set A from an arbitrary supernode. Repeatedly add the supernode outside A with the largest total weight into A.
  3. The last supernode added, t, and the previous one, s, are the phase pair. The total weight of edges between t and the rest of the graph is a candidate cut. Record it and the partition it names, expanded back to original vertices.
  4. Contract s and t into one supernode. Edges from both to a third supernode become one summed edge.
  5. Repeat until a phase has only two supernodes left. Return the lightest candidate recorded.

The result is a global cut of an undirected graph, not an s-t cut for a pair the caller named, and not a spanning tree. Karger’s algorithm estimates the same cut randomly and can miss it on one run. A flow algorithm computes the cut only after a source and a sink are chosen.


Approaches that look simpler and fail

Approach Why it fails when the phase cut is read as an s-t request
Stop after one phase The first phase cut is a min-cut for the pair of vertices finished last in that phase. Another pair can have a lighter global cut, found only after contraction.
Add the lightest neighbor instead of the tightest vertex Tightness is the total weight into the whole set A, the Prim-style key. The single lightest edge is a different growth rule.
Run it on a directed graph unchanged Contraction and tightness use undirected weight. A directed min-cut needs a flow.
Keep parallel edges as a single unweighted edge after contraction The cut value is a sum of weights. Dropping multiplicity undercounts every later phase.

An s-t minimum cut belongs to a maximum-flow algorithm. A Monte Carlo global cut belongs to Karger. Stoer-Wagner is the deterministic global algorithm between them.


A working example

This Python fragment grows a phase by the tightest connection to the set, records the cut of the last vertex, then contracts the last two vertices. The lightest phase cut of a triangle with unit edges is 2.

def stoer_wagner(graph):
    nodes = list(graph)
    best = 10**9
    while len(nodes) > 1:
        used = [nodes[0]]
        weight = {v: graph[nodes[0]].get(v, 0) for v in nodes[1:]}
        prev = nodes[0]
        for _ in range(len(nodes) - 1):
            u = max(weight, key=weight.get)
            used.append(u)
            prev = u
            del weight[u]
            for v in weight:
                weight[v] += graph[u].get(v, 0)
        last = used[-1]
        before = used[-2]
        cut = sum(graph[last].get(v, 0) for v in nodes if v != last)
        best = min(best, cut)
        for v in nodes:
            if v != before and v != last:
                graph[before][v] = graph[v][before] = graph[before].get(v, 0) + graph[last].get(v, 0)
        for v in nodes:
            graph[v].pop(last, None)
        nodes.remove(last)
        del graph[last]
    return best

g = {0: {1: 1, 2: 1}, 1: {0: 1, 2: 1}, 2: {0: 1, 1: 1}}
assert stoer_wagner(g) == 2
print(2)

Where it is used

Stoer-Wagner computes a deterministic global minimum cut, the fewest edges whose removal splits a network. Reliability and vulnerability studies use that cut. Karger’s algorithm estimates the same cut by random contraction and can miss.


When you can drop this algorithm

Drop Stoer-Wagner when the cut must separate a designated source from a designated sink. Use a flow. Keep it for an undirected global min-cut, and use the O(V³) matrix form unless the graph is sparse enough that the heap pays for itself.


Why this stays published

We publish this so a search for Stoer-Wagner returns the phase cut of the last vertex and the contraction that makes the minimum over phases global. Stoer-Wagner finds an undirected global min-cut by recording the last vertex’s cut in each Prim-like phase and then contracting that vertex with the one before it.

本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。

Leave a Reply

Your email address will not be published. Required fields are marked *