{"id":146,"date":"2026-11-13T12:32:42","date_gmt":"2026-11-13T04:32:42","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-boruvka-merges-components-by-their-cheapest-edge\/"},"modified":"2026-11-13T21:51:17","modified_gmt":"2026-11-13T13:51:17","slug":"how-boruvka-merges-components-by-their-cheapest-edge","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-boruvka-merges-components-by-their-cheapest-edge\/","title":{"rendered":"How Boruvka merges components by their cheapest edge"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Bor\u016fvka&#8217;s algorithm<\/strong> contracts many pieces of a minimum spanning tree at once. In each round every component marks a cheapest edge that leaves it, and all of those edges are added together. The number of components at least halves, so there are <strong>O(log V)<\/strong> rounds and the total time is <strong>O(E log V)<\/strong>. It is the oldest of the classical minimum-spanning-tree algorithms, and the one that parallelizes most directly.<\/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\">Prim grows one component. Kruskal adds one edge. On a parallel machine, or in a proof that wants a logarithmic number of phases, every component can choose at the same time. The cheapest edge leaving a component is safe by the cut property. Two components may choose the same edge. Distinct choices may also form a path or a star. They do not form a cycle in which every vertex has chosen the next edge, except in the case of equal weights, which needs a tie break.<\/p>\n\n\n<p class=\"wp-block-paragraph\">A deterministic tie break, such as the edge of smallest index among lightest edges, keeps the simultaneous choices acyclic. Without it, two components can each select a different equal-weight edge and close a cycle.<\/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\">Each round adds a forest of safe edges and at least halves the component count, because every component is joined to at least one other. A connected graph therefore finishes in O(log V) rounds. Each round scans every edge, so the total is O(E log V). Extra memory is the component label and the chosen edge per component. The result is a minimum spanning tree.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Negative weights are allowed. The algorithm is the basis of several linear-time randomized and nearly linear deterministic MST algorithms, which add filtering steps on top of this contraction. Those improvements are not required to state Bor\u016fvka itself.<\/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>Start with each vertex as a component.<\/li>\n<li>In each round, give every component a slot for the cheapest outgoing edge, initially empty.<\/li>\n<li>Scan every edge. If it crosses components and is cheaper than the slot at either end, record it. Break ties by a total order on edge ids so both ends agree.<\/li>\n<li>Add every recorded edge and merge the components it connects. A union-find structure, or a contraction of the adjacency list, performs the merge.<\/li>\n<li>Repeat until one component remains, or a round finds a component with no outgoing edge. That component is a connected component of the original graph.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">Simultaneous contraction computes the same tree Prim and Kruskal compute, up to tie breaking. It is not a shortest-path algorithm. The halving argument fails if a component is allowed to choose an internal edge. The scan has to ignore edges whose ends already share a label.<\/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 every component does not pick a true outgoing minimum<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Break equal weights arbitrarily, with no shared rule<\/td>\n<td>Component A can choose edge e1 and component B can choose edge e2, and the two edges can close a cycle when other choices are included. A total order on ties prevents it.<\/td>\n<\/tr>\n<tr>\n<td>Let a component pick its cheapest internal edge<\/td>\n<td>The edge does not cross the cut. Adding it creates a cycle inside the component.<\/td>\n<\/tr>\n<tr>\n<td>Assume the round count is constant<\/td>\n<td>A path-shaped contraction can take \u0398(log V) rounds. The logarithm is part of the bound.<\/td>\n<\/tr>\n<tr>\n<td>Contract and discard original endpoints<\/td>\n<td>The output has to be the original edges that were chosen. A supervertex that forgets which edge joined it cannot return the tree.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">Sequential one-edge growth belongs to Prim and Kruskal. Bor\u016fvka is the phase algorithm to reach for when every component should work at once, and it is the starting point of the faster theoretical MST algorithms.<\/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 gives every component its cheapest outgoing edge at once and merges those edges. Ties break by the smaller edge id, so two components cannot choose a cycle of two equal claims. It prints the MST weight <code>6<\/code>.<\/p>\n\n<pre><code class=\"language-python\">edges = [(0, 1, 1, 0), (1, 2, 2, 1), (0, 2, 4, 2), (2, 3, 3, 3), (1, 3, 5, 4)]  # u v w id\nparent = list(range(4))\n\ndef find(x):\n    while parent[x] != x:\n        parent[x] = parent[parent[x]]\n        x = parent[x]\n    return x\n\nchosen = []\nwhile len({find(i) for i in range(4)}) &gt; 1:\n    best = {}\n    for u, v, w, eid in edges:\n        a, b = find(u), find(v)\n        if a == b:\n            continue\n        for src, dst in ((a, b), (b, a)):\n            cand = (w, eid, dst)\n            if src not in best or cand &lt; best[src]:\n                best[src] = cand\n    for src, (w, eid, dst) in best.items():\n        a, b = find(src), find(dst)\n        if a != b:\n            parent[a] = b\n            chosen.append(w)\nprint(sum(chosen))\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\">Bor\u016fvka&#8217;s algorithm grows a minimum spanning tree by merging every component along its cheapest edge at once, which is the step parallel MST codes use. Kruskal and Prim are the sequential algorithms in network-layout tools. The tree is the same.<\/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 Bor\u016fvka in a short sequential program if Kruskal&#8217;s sort is easier to verify. Keep it when a logarithmic number of parallel rounds is the model you are programming, or when a later linear-time MST proof is being reduced to this contraction.<\/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 Bor\u016fvka returns the simultaneous cheapest-outgoing edge and the halving of the component count. <strong>Bor\u016fvka&#8217;s algorithm adds every component&#8217;s cheapest outgoing edge in one round, halves the number of components, and finishes a minimum spanning tree in O(E log V) time.<\/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: Bor\u016fvka&#8217;s algorithm contracts many pieces of a minimum spanning tree at once. In each round every component marks a cheapest edge that leaves it, and all of those edges are added together. The number of components at least halves, so there are O(log V) rounds and the&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-146","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\/146","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=146"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":545,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/146\/revisions\/545"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}