The Daily Reckoning
How Can the Cheapest Network Emerge One Edge at a Time?
Kruskal's algorithm builds a minimum spanning tree by taking the cheapest edge that does not create a cycle—and an exchange argument explains why the greedy choice is safe.
- Difficulty
- Intermediate
- Area
- Discrete mathematics and optimization
- Reading time
- 9 minutes
- Prerequisites
- Reading a weighted graph · Addition and inequalities · Basic set and grouping ideas
Six islands need a cable network. Every possible cable has a quoted cost. You want every island to reach every other island, perhaps through intermediate islands, and you want the total cost as low as possible.
Must you compare every complete network?
For the network in this lesson, there are 185 different loop-free ways to connect all six islands. A rule published by Joseph Kruskal in 1956 finds the cheapest one by making one local decision repeatedly:
Inspect the cables from cheapest to most expensive. Take a cable unless taking it would create a loop.
This is a greedy algorithm: it commits to the best-looking available move without searching all future combinations. Greedy rules often fail. The cheapest airfare for each leg need not produce the cheapest whole journey. Kruskal’s rule succeeds because trees have a useful exchange property.
What counts as a cheapest network?
A weighted graph is a pair together with a weight function . The set contains the vertices, which represent the six islands. The set contains edges, which represent available cables between pairs of islands. For an edge , the number is its cost.
A spanning tree is a collection of edges that has two properties:
- every vertex can be reached from every other vertex by following edges in ;
- contains no cycle, meaning no closed route that returns to its starting vertex without retracing an edge.
For a graph with vertices, every spanning tree has exactly edges. The six-island network therefore needs five edges. Fewer than five cannot connect all six vertices; more than five would force a cycle.
The total weight of a spanning tree is
The symbol means to add the weights of every edge in . A minimum spanning tree is a spanning tree whose total weight is no larger than the total weight of any other spanning tree of the same graph.
The diagram below carries out Kruskal’s rule. At the start, each vertex is its own connected component. A connected component is a group of vertices already joined by accepted edges.
Greedy network chart
Take the cheapest edge that does not close a loop
Start · 0 of 6 decisions
Work the example without a jump
The relevant edges arrive in this order:
The letters name an edge’s endpoints; the number in parentheses is its weight. Here is every decision before the tree is complete.
Step 1: take , weight . Vertices and belong to different components, so the edge cannot create a cycle. The running total is .
Step 2: take , weight . Vertex is separate from the component . The accepted edges are now and , and the running total is
Step 3: take , weight . Vertices and are separate. The components are now , , and . The running total is
Step 4: take , weight . This edge joins to . Two components remain: and . The running total is
Step 5: skip , weight . Vertices and are already connected by the path . Adding would close the cycle . The running total stays .
Step 6: take , weight . This edge joins the two remaining components. The five accepted edges now connect all six vertices, so the algorithm stops. Their total weight is
An exhaustive computer check provides an independent verification: the graph has 185 spanning trees, the next-best total is , and the tree of weight is the unique minimum.
Why the greedy choice is safe
The calculation shows what Kruskal’s algorithm does. The proof must explain why a cheap edge accepted now cannot force an expensive mistake later.
Suppose the algorithm is about to accept an edge . Its endpoints lie in different connected components of the edges already accepted. Imagine drawing a boundary around either one of those components. The edge crosses that boundary, and no cheaper unexamined edge crosses it; otherwise the cheaper edge would have appeared earlier.
Now choose a minimum spanning tree that contains all edges accepted before . Such a tree exists at the first step; the argument below shows how to preserve its existence after every step.
There are two cases.
Case 1: already contains . Nothing needs to change.
Case 2: does not contain . Add temporarily to . Because already connects every vertex, the added edge creates exactly one cycle. That cycle must cross the component boundary once to leave and again to return. Let be another edge on the cycle that crosses the boundary.
The algorithm considered edges in nondecreasing order, so
Remove . The cycle opens, but every vertex stays connected. The new collection
is a spanning tree. Its weight satisfies
The tree was already minimum, so is also minimum. More importantly, contains every previously accepted edge and now contains as well.
This replacement is called an exchange argument. After every accepted edge, at least one minimum spanning tree remains compatible with all decisions made so far. When the algorithm has accepted edges, those edges themselves form a minimum spanning tree.
Equal weights cause no difficulty. They can allow several minimum spanning trees, but the inequality still holds, so Kruskal’s algorithm finds one of them.
The problem came before the name
The minimum-spanning-tree problem did not begin with Kruskal. In 1926, Czech mathematician Otakar Borůvka published the first known solution while studying the economical construction of electrical networks. His original formulation asked for a shortest network joining given points, and one of his two 1926 papers explicitly concerned electricity-power networks. The historical setting matters: the abstract graph problem grew from the physical task of extending infrastructure while limiting total construction length.
Borůvka used a different greedy procedure: from every current component, choose its cheapest outgoing edge, then merge the resulting components and repeat. A scholarly translation and history preserved by the Czech Digital Mathematics Library places both original papers together and shows how the problem became a cornerstone of combinatorial optimization.
Joseph B. Kruskal published the edge-by-edge rule taught here in “On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem” in 1956. Kruskal’s three-page paper appeared during a period when the newly developing theory of algorithms and computer science made minimum-spanning-tree methods a focus of renewed attention. Robert Prim published another influential method in 1957; Vojtěch Jarník had already described that tree-growing approach in 1930. The history is a chain of formulations, rediscoveries, and improvements—not a single flash attached to one surname.
Where minimum spanning trees earn their keep
The cable story is a direct application when an edge’s weight measures the cost of building a link and intermediate connections are allowed. The same mathematics applies to laying pipeline, road, or communication backbones under that simplified objective. Real projects add capacity, reliability, terrain, regulation, and redundancy constraints; a tree has no backup route if one edge fails. A minimum spanning tree is therefore often a baseline or a subproblem rather than a finished engineering plan.
Minimum spanning trees also encode single-linkage clustering. Suppose vertices represent data points and an edge weight is the distance between two points. If is the number of groups you want, build a minimum spanning tree and cut its heaviest edges. The remaining components give the same grouping as single-linkage clustering at that level. J. C. Gower and G. J. S. Ross established the relationship in their 1969 paper “Minimum Spanning Trees and Single Linkage Cluster Analysis”.
The application changes the interpretation but not the rule. A cable cost, a geographic distance, and a dissimilarity score can all serve as ; the algorithm only needs weights it can compare.
Try the rule
Problem 1
After accepting and in the worked graph, why must Kruskal’s algorithm reject , even though its weight is smaller than the weight of the final accepted edge?
Reveal the solution
The accepted edges and already provide the path . Adding would close the cycle
Kruskal’s algorithm rejects an edge whenever its endpoints already belong to the same connected component. The later edge is heavier, but its endpoints lie in different components when it is considered, so performs necessary work: it joins to .
Problem 2
A graph has vertices and weighted edges
Run Kruskal’s algorithm. Which edges enter the minimum spanning tree, and what is its total weight?
Reveal the solution
Read the edges in the displayed order.
- Accept . It joins two separate vertices.
- Accept . It joins two other separate vertices.
- Accept . It joins the component to the component .
All four vertices are connected after three edges. A spanning tree on four vertices has edges, so the algorithm stops. The total weight is
The idea to keep
Kruskal’s algorithm accepts the cheapest edge that connects two different components. The exchange argument guarantees that each accepted edge can belong to a minimum spanning tree, so a sequence of safe local choices becomes a globally cheapest loop-free network.
To continue, Can You Cross Every Bridge Exactly Once? introduces graphs through Euler’s route problem, Why Do the Shortest Three Roads Meet at 120°? allows new junctions in a related network-design problem, and Why Must Every Network Have an Even Number of Odd Junctions? proves another structural fact about graph edges.
Sources
- Paul E. Black, National Institute of Standards and Technology, “Kruskal’s algorithm”, concise algorithm definition.
- Joseph B. Kruskal, “On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem”, Proceedings of the American Mathematical Society 7 (1956), 48–50.
- Jaroslav Nešetřil, Eva Milková, and Helena Nešetřilová, “Otakar Borůvka on Minimum Spanning Tree Problem: Translation of Both the 1926 Papers, Comments, History”, Discrete Mathematics 233 (2001), 3–36.
- Robert Sedgewick and Kevin Wayne, Princeton University, “Minimum Spanning Trees”, algorithms, cut property, and implementations.
- J. C. Gower and G. J. S. Ross, “Minimum Spanning Trees and Single Linkage Cluster Analysis”, Journal of the Royal Statistical Society: Series C 18 (1969), 54–64.