VLVisual Learner

Borůvka's Algorithm

Time: O(E log V)At most log V roundsGreedy · easy to parallelise
–
Pseudocode
1every vertex starts as its own component
2while more than one component is left:
3 for each component C:
4 find the cheapest edge leaving C
5 add all those edges to the MST (skip one if its ends are already joined)
6 merge the components they connect
Round
0
Components
0
colourone componentcheapest edge leaving a componentin the MST

What is Borůvka's Algorithm?

Borůvka's algorithm (1926) is the oldest minimum spanning tree algorithm. Like Prim's and Kruskal's, it builds the cheapest set of edges that connects every vertex.

It works in rounds. In each round, every component at once picks the cheapest edge that leaves it. All those edges are added, the components they connect merge, and the next round starts with fewer, bigger components. Since each component joins at least one other, the number of components at least halves every round.

Every component grabs its cheapest outgoing edge, all at the same time.

Using the Visualizer

  • • Each colour is one component. In each round, yellow edges are the cheapest edge leaving some component.
  • • Green edges are in the MST. Two components can pick the same edge; it is only added once.
  • • Use the same example as on the Prim and Kruskal pages and compare: the total weight is the same.

How It Works

1. Start

Every vertex is a component by itself.

2. Cheapest edge out

Each component finds its cheapest edge to a different component.

3. Add and merge

Add all chosen edges (skipping duplicates) and merge the components.

4. Repeat

Until one component remains, or no edge leaves a component (disconnected graph).
Ties: with equal weights, two components could choose edges that form a cycle. Breaking ties by a fixed rule (here: by vertex numbers) prevents that.

Implementation

// Borůvka's algorithm. edges = [[u, v, w], ...] for an undirected graph.
function boruvka(n, edges) {
  const parent = [...Array(n).keys()];
  const find = (x) => (parent[x] === x ? x : (parent[x] = find(parent[x])));
  const mst = [];
  let components = n;

  while (components > 1) {
    // cheapest edge leaving each component (ties broken by vertex numbers)
    const cheapest = Array(n).fill(null);
    for (const e of edges) {
      const [u, v, w] = e;
      const a = find(u), b = find(v);
      if (a === b) continue;
      for (const c of [a, b])
        if (!cheapest[c] || w < cheapest[c][2]) cheapest[c] = e;
    }
    let added = 0;
    for (const e of cheapest) {
      if (!e) continue;
      const a = find(e[0]), b = find(e[1]);
      if (a === b) continue;            // already joined this round
      parent[a] = b;
      mst.push(e);
      components--;
      added++;
    }
    if (added === 0) break;             // disconnected: a forest is all we get
  }
  return mst;
}

Properties & Complexity

Time Complexity

  • • Rounds: at most log₂ V
  • • Each round: O(E) to scan the edges
  • • Total: O(E log V)

Space & Properties

  • • Space: O(V) for union-find and the cheapest edges
  • • Result: same total weight as Prim and Kruskal

Where It Is Used

  • • Parallel and distributed MST computation (components work independently)
  • • Network design and clustering, like the other MST algorithms
  • • Building block of faster MST algorithms (Karger–Klein–Tarjan)

Limitations

  • • Needs tie-breaking when weights repeat
  • • Sequentially no faster than Kruskal or Prim
  • • Undirected graphs only