A minimum spanning tree connects every node with the least total edge weight — the cheapest way to wire a network with no redundant loops. Kruskal’s algorithm (1956) builds it greedily and globally: sort all edges by weight, then add each in turn unless it would form a cycle — and union-find (dart 518) is exactly the cycle test (endpoints already in the same set). Take the cheapest safe edges and you have the optimum, provably. It pairs with Prim (dart 526), which grows the tree locally; both reach the same minimum weight. Here that weight is 7.
The demo builds an MST by adding the cheapest cycle-free edges (via union-find) — total weight 7: live demo
“Greedy algorithms give approximate answers.” — for the MST, taking the cheapest safe edge each time is provably optimal. cited
A network wired at least cost by taking cheap edges and refusing loops — greedy, and exactly optimal. resource
On the canonical compiler, Kruskal (cheapest cycle-free edges via union-find) builds an MST of total weight 7: