Implement a minimum spanning tree using Boruvkas algorithm I
Implement a minimum spanning tree using Boruvka\'s algorithm.
Implement a minimum spanning tree using Boruvka\'s algorithm.
Solution
The psuedo code is as follows:
1 Graph input = /* read input */;
2 UnionFind uf (input.getNodes ());
3 Workset ws = input.getNodes();
4 foreach (Node n : ws) {
5 Edge e = minWeight (input.getOutEdges (n));
6 Node rep1 = uf.find (e.src);
7 Node rep2 = uf.find (e.dst);
8 if (rep1 != rep2) {
9 e.markInMST();
10 Node rep = uf.union (rep1, rep2);
11 ws.add (rep)
12 }
13 }
