{"id":206,"date":"2026-11-13T12:34:33","date_gmt":"2026-11-13T04:34:33","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-karger-contracts-a-random-min-cut\/"},"modified":"2026-11-13T21:52:44","modified_gmt":"2026-11-13T13:52:44","slug":"how-karger-contracts-a-random-min-cut","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-karger-contracts-a-random-min-cut\/","title":{"rendered":"How Karger contracts a random min-cut"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Karger&#8217;s algorithm<\/strong> finds a global minimum cut of an undirected multigraph by randomly contracting edges until two supernodes remain. The edges between those two supernodes are a cut, and each run returns the minimum cut with probability at least <strong>1\/binom(n, 2)<\/strong>, about <strong>2\/n\u00b2<\/strong>. Repeating <strong>O(n\u00b2 log n)<\/strong> independent runs and keeping the lightest cut raises the failure probability below 1\/n. One run is <strong>O(E)<\/strong> with a suitable graph representation, or <strong>O(n\u00b2)<\/strong> in the usual adjacency form.<\/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 is a partition of the vertices into two nonempty sides with as few edges across as possible. It is not an s-t cut for a designated pair, and it is not a spanning tree. Flows compute an s-t cut. Karger&#8217;s observation is that a random contraction keeps every edge of a fixed min-cut alive with a probability that is only polynomially small.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Contraction of an edge merges its endpoints and destroys self-loops, while edges to the rest of the graph become parallel edges. Parallel edges matter. The cut value is a count of edges, or a sum of weights if the algorithm is extended carefully. The basic algorithm is unweighted.<\/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\">A single run returns some cut. For any fixed minimum cut, the probability that no contracted edge belonged to it is at least 2\/(n(n\u22121)). Therefore O(n\u00b2 log n) independent runs include that cut, and hence some minimum cut, with probability at least 1 \u2212 1\/n. The algorithm can return a cut that is not minimum on any one run. The repetition is part of the method, not an optional booster.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Fast implementations use Karger\u2013Stein contraction, which stops the random contraction early and recurses twice, improving the repetition count. The basic algorithm&#8217;s probability is the one to learn first. Stoer\u2013Wagner computes a global min-cut deterministically. Karger is the randomized existence proof that became an algorithm.<\/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>Copy the undirected multigraph. Parallel edges stay parallel. Self-loops are irrelevant and should be dropped.<\/li>\n<li>While more than two supernodes remain, pick an edge uniformly from the remaining multiset and contract it. Replace the two ends by one supernode, delete self-loops, and keep parallel edges to other supernodes.<\/li>\n<li>The surviving edges between the last two supernodes form a cut. Record its size.<\/li>\n<li>Repeat from a fresh copy O(n\u00b2 log n) times, or a larger constant times that. Keep the smallest cut observed, together with the partition that produced it.<\/li>\n<li>If edge weights must be handled, contract with probability proportional to weight only in the weighted variant. The unweighted proof picks an edge uniformly.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">The probability bound is for one fixed min-cut surviving a uniform random contraction. It does not say one run is probably optimal. It says one run succeeds with probability \u03a9(1\/n\u00b2). An s-t minimum cut with capacities belongs to a flow algorithm. A deterministic global min-cut belongs to Stoer-Wagner.<\/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 one contraction is treated as the answer<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Return the first two-supernode cut<\/td>\n<td>That cut is some cut. The success probability of one run is only about 2\/n\u00b2, so a single run is usually not minimum on a large graph.<\/td>\n<\/tr>\n<tr>\n<td>Contract vertices instead of a random edge<\/td>\n<td>Merging a random pair that is not an edge skips the probability proof and can separate a min-cut edge early.<\/td>\n<\/tr>\n<tr>\n<td>Drop parallel edges after contraction<\/td>\n<td>The cut value counts multiplicity. Collapsing parallels undercounts the cut and changes which edge is chosen next.<\/td>\n<\/tr>\n<tr>\n<td>Use the algorithm for an s-t cut and force s and t to stay apart<\/td>\n<td>That modification is a different procedure. The basic probability is for an unrestricted global cut.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">A deterministic global min-cut is Stoer-Wagner. An s-t cut is a maximum flow. Karger\u2013Stein is the recursive contraction schedule that reduces the number of repetitions.<\/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 contracts a random edge and keeps parallel edges, then repeats. The graph is a 4-cycle with one diagonal. Over seeded trials the lightest cut found is the bridge-free min cut of weight <code>2<\/code>.<\/p>\n\n<pre><code class=\"language-python\">import random\nedges = [(0, 1), (1, 2), (2, 3), (3, 0), (0, 2)]  # unit weights, min cut 2\n\ndef contract_once(rng):\n    comp = list(range(4))\n    alive = 4\n    pool = edges[:]\n    while alive &gt; 2:\n        u, v = pool[rng.randrange(len(pool))]\n        if comp[u] == comp[v]:\n            continue\n        survivor, doomed = comp[u], comp[v]\n        for i in range(4):\n            if comp[i] == doomed:\n                comp[i] = survivor\n        alive -= 1\n        pool = [(a, b) for a, b in pool if comp[a] != comp[b]]\n    return len(pool)\n\nbest = min(contract_once(random.Random(seed)) for seed in range(40))\nassert best == 2\nprint(best)\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\">Karger&#8217;s contractions estimate a global minimum cut of a network by randomly merging vertices. It is a Monte Carlo check of connectivity. <strong>Stoer-Wagner<\/strong> is the deterministic min-cut a reliability calculation can cite without a failure probability.<\/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 basic Karger when a deterministic answer is required and n is small enough for Stoer-Wagner. Keep the repeated contractions when a simple Monte Carlo global min-cut is acceptable and the failure probability is driven down by the O(n\u00b2 log n) repetitions.<\/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 Karger&#8217;s algorithm returns the 1\/n\u00b2 success probability of one run and the repetitions that make it reliable. <strong>Karger&#8217;s algorithm returns a global min-cut by random edge contraction, and one run succeeds with probability only about 2\/n\u00b2, so the algorithm repeats.<\/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: Karger&#8217;s algorithm finds a global minimum cut of an undirected multigraph by randomly contracting edges until two supernodes remain. The edges between those two supernodes are a cut, and each run returns the minimum cut with probability at least 1\/binom(n, 2), about 2\/n\u00b2. Repeating O(n\u00b2 log n)&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-206","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\/206","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=206"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/206\/revisions"}],"predecessor-version":[{"id":605,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/206\/revisions\/605"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}