The Stoer–Wagner minimum cut algorithm #
The Stoer–Wagner algorithm [SW97] computes a global minimum cut of a weighted
multigraph W : Fin n → Fin n → ℕ (Cslib.WeightedCut.IsMultigraph) deterministically. Each
phase computes a maximum adjacency ordering of the current supervertices by maximum adjacency
search (Cslib.WeightedCut.maSearch), records the cut of the phase, the cut {t} of its last
vertex t, and merges t into the second to last vertex s. After n - 1 phases one supervertex
is left, and the lightest cut of the phase is a global minimum cut.
Correctness has two parts. By the MA-ordering lemma
(Cslib.WeightedCut.cutWeight_singleton_le_of_isMAOrdering), the cut of the phase weighs at most
every cut separating s and t. A cut not separating s and t survives merging them with the
same weight (Cslib.WeightedCut.cutWeight_contractCut), so the minimum cut weight is the smaller of
the weight of the cut of the phase and the minimum cut weight after the merge
(minCut_eq_min_contractMatrix, the phase recursion of [SW97]). Contraction is that of
CslibFrontier.Foundations.Combinatorics.WeightedCut.Contraction (contractMatrix,
contractPart),
which keeps the supervertices as Fin m and moves the last one into the freed slot; it is shared
with Karger's algorithm and needs no probability.
Main definitions #
Cslib.Algorithms.Lean.StoerWagner.maOrder: a maximum adjacency ordering ofFin k.Cslib.Algorithms.Lean.StoerWagner.run: the phases on the supervertices of a contraction.Cslib.Algorithms.Lean.StoerWagner.stoerWagner: the algorithm, answering one side of a minimum cut and its weight.Cslib.Algorithms.Lean.StoerWagner.stoerWagnerM: the algorithm inTimeM, with a cost model.
Main results #
Cslib.Algorithms.Lean.StoerWagner.minCut_eq_min_contractMatrix,Cslib.Algorithms.Lean.StoerWagner.minCut_eq_min_minCutBetween: the phase recursion.Cslib.Algorithms.Lean.StoerWagner.minCut_eq_min_of_isMAOrdering: one phase.Cslib.Algorithms.Lean.StoerWagner.stoerWagner_spec: the algorithm answers a non-trivial cut of minimum weight, and its weight.Cslib.Algorithms.Lean.StoerWagner.time_stoerWagnerM_le: at mostn ^ 3 + 4 n ^ 2steps.
Cost model #
stoerWagnerM charges unit cost per scanned entry of an array implementation with machine-word
arithmetic on weights, as the TimeM annotations of the other algorithms here do; the charges are
TimeM.tick annotations in the program, not derived from the Lean evaluation, which uses
closures. For a phase on m supervertices of a graph on n vertices:
- initializing the key array costs
m; - a search step on
rremaining candidates costs2 r - 1: a scan for the largest key and an update of the otherr - 1keys, so the search costsm ^ 2; - recording the cut of the phase costs
m + n: its degree, and the vertex set of the original graph mapped tot; - the merge costs
4 m + n + 1: adding row and columntof the weight matrix into those ofs(2 m), moving row and columnm - 1into the freed slott(2 m), relabelling the original vertices (n) and comparing two weights (1).
The final phase, on two supervertices, needs no search and costs 2 + n. One-time setup is not
charged: the weight matrix is taken as given, and the initial map part = id of the n original
vertices to supervertices is free. The total is at most n ^ 3 + 4 n ^ 2 (time_stoerWagnerM_le).
This bound is loose. Summing the charges by hand, a phase on m ≥ 3 supervertices costs
m ^ 2 + 6 m + 2 n + 1, so the charged time is n ^ 3 / 3 + O(n ^ 2); only the weaker bound is
proved. On the 8-vertex example of the tests the charged time is 509, against the bound 768.
This is the O(n³) array version of the algorithm; the O(n m + n² log n) bound of
[SW97] uses Fibonacci heaps and is not formalized here.
Limitations #
Weights are natural numbers, as in Cslib.WeightedCut; rational weights can be scaled to natural
numbers, real weights are not covered. The algorithm answers one minimum cut, not all of them.
References #
The algorithm #
maOrder W lists every vertex once.
The phases of the algorithm on the supervertices Fin (k + 2) of the contraction
part : Fin n → Fin (k + 2) of the input. A phase computes a maximum adjacency ordering, ending
with s, t, and merges t into s; the answer is the cut of the phase, the original vertices
mapped to t, unless the phases after the merge find a cut at most as heavy. With two
supervertices left the cut of the single phase is that of supervertex 1.
Instances For
Correctness #
The phase recursion of [SW97]: if X is a minimum cut separating s and t,
the global minimum cut weight is the smaller of the weight of X and the global minimum cut weight
after merging t into s.
The phase recursion in terms of the minimum s–t cut weight λ(s, t)
(Cslib.WeightedCut.minCutBetween): for distinct s and t, the global minimum cut weight is
min (λ(s, t)) (minCut (contractMatrix W s t)).
One phase: for the last two vertices s, t of a maximum adjacency ordering, the global
minimum cut weight is the smaller of the weight of the cut of the phase {t} and the global
minimum cut weight after merging t into s.
The phases on a contraction of W₀ answer a non-trivial cut of W₀ with its weight, and that
weight is the global minimum cut weight of the contraction.
Correctness of the Stoer–Wagner algorithm [SW97]: on a multigraph with at least two vertices it answers a non-trivial cut of minimum weight, and the weight of that cut.
Cost #
Maximum adjacency search (Cslib.WeightedCut.maSearch) in TimeM: a step on r remaining
candidates costs 2 r - 1, a scan for the largest key and an update of the other keys.
Instances For
maSearchM computes maSearch.
stoerWagner in TimeM, with the charges of the cost model.
Instances For
stoerWagnerM computes stoerWagner.
The cost of the Stoer–Wagner algorithm: at most n ^ 3 + 4 n ^ 2 steps on n vertices in
the cost model of the module docstring, which does not charge one-time setup. The bound is not
tight: the leading term of the charged time is n ^ 3 / 3.