{"id":260,"date":"2026-11-13T12:36:12","date_gmt":"2026-11-13T04:36:12","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-stoer-wagner-finds-a-global-min-cut\/"},"modified":"2026-11-13T21:53:54","modified_gmt":"2026-11-13T13:53:54","slug":"how-stoer-wagner-finds-a-global-min-cut","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-stoer-wagner-finds-a-global-min-cut\/","title":{"rendered":"How Stoer-Wagner finds a global min-cut"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Stoer-Wagner<\/strong> 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 <strong>O(VE + V\u00b2 log V)<\/strong> time, and a simple array scan is <strong>O(V\u00b3)<\/strong>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">The minimum of the phase cuts equals the global minimum cut. There are V\u22121 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\u00b2 log V). The array implementation, which scans for the tightest vertex each time, is O(V\u00b3) 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.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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 &#8220;most tightly connected&#8221; the wrong greedy choice for a cut. Zero-weight edges are fine.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Represent the undirected graph so parallel edges combine by adding weights. Start with the original vertices as the supernodes.<\/li>\n<li>In a phase, grow a set A from an arbitrary supernode. Repeatedly add the supernode outside A with the largest total weight into A.<\/li>\n<li>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.<\/li>\n<li>Contract s and t into one supernode. Edges from both to a third supernode become one summed edge.<\/li>\n<li>Repeat until a phase has only two supernodes left. Return the lightest candidate recorded.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">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&#8217;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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when the phase cut is read as an s-t request<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Stop after one phase<\/td>\n<td>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.<\/td>\n<\/tr>\n<tr>\n<td>Add the lightest neighbor instead of the tightest vertex<\/td>\n<td>Tightness is the total weight into the whole set A, the Prim-style key. The single lightest edge is a different growth rule.<\/td>\n<\/tr>\n<tr>\n<td>Run it on a directed graph unchanged<\/td>\n<td>Contraction and tightness use undirected weight. A directed min-cut needs a flow.<\/td>\n<\/tr>\n<tr>\n<td>Keep parallel edges as a single unweighted edge after contraction<\/td>\n<td>The cut value is a sum of weights. Dropping multiplicity undercounts every later phase.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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 <code>2<\/code>.<\/p>\n\n<pre><code class=\"language-python\">def stoer_wagner(graph):\n    nodes = list(graph)\n    best = 10**9\n    while len(nodes) &gt; 1:\n        used = [nodes[0]]\n        weight = {v: graph[nodes[0]].get(v, 0) for v in nodes[1:]}\n        prev = nodes[0]\n        for _ in range(len(nodes) - 1):\n            u = max(weight, key=weight.get)\n            used.append(u)\n            prev = u\n            del weight[u]\n            for v in weight:\n                weight[v] += graph[u].get(v, 0)\n        last = used[-1]\n        before = used[-2]\n        cut = sum(graph[last].get(v, 0) for v in nodes if v != last)\n        best = min(best, cut)\n        for v in nodes:\n            if v != before and v != last:\n                graph[before][v] = graph[v][before] = graph[before].get(v, 0) + graph[last].get(v, 0)\n        for v in nodes:\n            graph[v].pop(last, None)\n        nodes.remove(last)\n        del graph[last]\n    return best\n\ng = {0: {1: 1, 2: 1}, 1: {0: 1, 2: 1}, 2: {0: 1, 1: 1}}\nassert stoer_wagner(g) == 2\nprint(2)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Stoer-Wagner computes a deterministic global minimum cut, the fewest edges whose removal splits a network. Reliability and vulnerability studies use that cut. Karger&#8217;s algorithm estimates the same cut by random contraction and can miss.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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\u00b3) matrix form unless the graph is sparse enough that the heap pays for itself.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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. <strong>Stoer-Wagner finds an undirected global min-cut by recording the last vertex&#8217;s cut in each Prim-like phase and then contracting that vertex with the one before it.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,32],"tags":[],"class_list":["post-260","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-graphs"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=260"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/260\/revisions"}],"predecessor-version":[{"id":659,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/260\/revisions\/659"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}