Borůvka's Algorithm (MST)
Parallel-friendly MST algorithm finding cheapest edge for each component iteratively.
Visualization
Interactive visualization for Borůvka's Algorithm (MST)
Interactive visualization with step-by-step execution
Implementation
1function boruvkaMST(n: number, edges: [number, number, number][]): number {
2 const parent = Array.from({length: n}, (_, i) => i);
3 const find = (x: number): number => parent[x] === x ? x : (parent[x] = find(parent[x]));
4 const union = (x: number, y: number) => { parent[find(x)] = find(y); };
5
6 let mstWeight = 0, numComponents = n;
7
8 while (numComponents > 1) {
9 const cheapest = new Array(n).fill(-1);
10
11 for (let i = 0; i < edges.length; i++) {
12 const [u, v, w] = edges[i];
13 const setU = find(u), setV = find(v);
14 if (setU !== setV) {
15 if (cheapest[setU] === -1 || edges[cheapest[setU]][2] > w) cheapest[setU] = i;
16 if (cheapest[setV] === -1 || edges[cheapest[setV]][2] > w) cheapest[setV] = i;
17 }
18 }
19
20 for (let i = 0; i < n; i++) {
21 if (cheapest[i] !== -1) {
22 const [u, v, w] = edges[cheapest[i]];
23 const setU = find(u), setV = find(v);
24 if (setU !== setV) {
25 mstWeight += w;
26 union(setU, setV);
27 numComponents--;
28 }
29 }
30 }
31 }
32 return mstWeight;
33}Deep Dive
Theoretical Foundation
Repeatedly finds cheapest edge leaving each component and merges components. O(log V) phases, each reducing components by half. Parallelizable.
Complexity
Time
O(E log V)
O(E log V)
O(E log V)
Space
O(V + E)
Applications
Industry Use
Parallel MST construction
Large-scale network design
Cluster analysis
Circuit layout optimization
Graph sparsification pre-processing
Distributed graph analytics
Use Cases
Related Algorithms
Depth-First Search (DFS)
Graph traversal exploring as deep as possible before backtracking. DFS is a fundamental algorithm that uses a stack (either implicitly through recursion or explicitly) to explore graph vertices. It's essential for cycle detection, topological sorting, and pathfinding problems.
Breadth-First Search (BFS)
Level-by-level graph traversal guaranteeing shortest paths in unweighted graphs. BFS uses a queue to explore vertices level by level, making it optimal for finding shortest paths and solving problems that require exploring nearest neighbors first.
Dijkstra's Algorithm
Finds shortest path from source to all vertices in weighted graph with non-negative edges. Uses greedy approach with priority queue.
Floyd-Warshall Algorithm
Floyd-Warshall is an all-pairs shortest path algorithm that finds shortest distances between every pair of vertices in a weighted graph. Unlike Dijkstra (single-source), it computes shortest paths from all vertices to all other vertices simultaneously. The algorithm can handle negative edge weights but not negative cycles. Developed independently by Robert Floyd, Bernard Roy, and Stephen Warshall in the early 1960s.