Infrastructure Networks as Weighted Graphs
Suppose a set of sites must be connected by cables, pipes or other links. Each possible link has a cost, and the aim is to connect every site while keeping the total cost as small as possible. A graph captures the choices: vertices represent sites, edges represent available links, and an edge’s weight records its cost.
In this model, assume each link’s cost is fixed and the total cost is the sum of the costs of the links chosen. We seek a network that connects all sites, but does not pay for a link that is unnecessary for connectivity. This is a minimum spanning tree problem. The model does not, by itself, account for capacity, reliability, backup routes or construction constraints; those may change which design is appropriate.
All graphs below are finite and simple, and their edges are undirected. For an infrastructure interpretation, assume the weights are costs, usually nonnegative. The algorithm and proof also work for real-valued weights. A connected graph has at least one spanning tree; if the available-link graph is disconnected, it is impossible to connect all sites using only those links. A tree is a connected graph with no cycle, so its links provide connectivity without a cycle of redundant links.
Kruskal’s Algorithm
Kruskal’s algorithm considers links in order of nondecreasing cost. It starts with no links selected. For each link in turn, it accepts the link if its endpoints are in different connected components of the links already selected; otherwise it rejects the link. In other words, accept a link exactly when adding it does not create a cycle. Stop when all vertices are connected. When costs tie, use any fixed order among tied edges.
The test for whether to accept an edge can be performed by checking whether its endpoints are already joined by a path of selected edges. If they are, adding it closes a cycle, so it is rejected. If they are not, it joins two components without creating a cycle. The selected edges therefore remain a forest throughout the process.
Why the Algorithm Is Correct
We prove that the algorithm produces a spanning tree of minimum cost. The proof uses an exchange argument: when the algorithm accepts a link, a minimum spanning tree can be adjusted to include it without increasing the total cost.
Proof. Let \(F\) be the set of edges accepted so far. We first show that at every stage, there is a minimum spanning tree containing \(F\). Initially \(F=\varnothing\), and a minimum spanning tree exists because the graph is finite and connected: it has at least one spanning tree, and there are only finitely many subgraphs to compare.
Suppose the algorithm accepts an edge \(e\), and assume there is a minimum spanning tree \(T\) containing all previously accepted edges. If \(e\in E(T)\), then \(T\) already contains the new set of accepted edges. Otherwise, adding \(e\) to \(T\) creates a cycle: the unique path in \(T\) between the endpoints of \(e\), together with \(e\), is a cycle. Let \(A\) and \(B\) be the two different components of the selected-edge forest just before \(e\) is accepted. The path in \(T\) between the endpoints of \(e\) must cross from \(A\) to \(B\). Choose an edge \(f\) on that path that crosses between these components.
The edge \(f\) is not among the previously accepted edges, since those edges lie within components of the forest. Also, \(f\) cannot have been processed before \(e\). If it had, its endpoints, which are in different components just before \(e\) is accepted, would also have been in different components when \(f\) was processed: components only merge as edges are accepted. The algorithm would then have accepted \(f\), a contradiction. Thus \(f\) is unprocessed, and the nondecreasing order gives \(w(f)\ge w(e)\).
Remove \(f\) from the cycle formed by adding \(e\) to \(T\), and call the resulting graph \(T'\). Removing an edge of that cycle keeps the graph connected, and the resulting graph has no cycle, so \(T'\) is a spanning tree. It contains the previously accepted edges and \(e\), and its cost is the cost of \(T\) plus \(w(e)-w(f)\), which is no greater than the cost of \(T\). Since \(T\) was already minimum-cost, \(T'\) is also a minimum spanning tree. This proves the claim at each accepted edge.
At the end, the selected edges connect all vertices. Indeed, if two or more components remained, connectedness of the original graph guarantees an edge between different components. When that edge was processed, its endpoints were also in different components, because components only merge; it would therefore have been accepted. This contradicts the claim that different components remain at the end. The selected edges form a connected forest, hence a spanning tree. By the claim, a minimum spanning tree contains all the selected edges; since both are spanning trees, they have the same number of edges, so they are equal. Therefore the algorithm’s output is minimum-cost. If the graph has one vertex and no edges, the algorithm returns the empty edge set, which is its spanning tree and is minimum-cost. \(\square\)
A finite tree on \(n\) vertices has \(n-1\) edges. For \(n\ge2\), a finite tree has a leaf: take a longest path, whose endpoint cannot have a neighbor outside the path (that would extend it) or another neighbor on the path (that would create a cycle). Removing the leaf and its single incident edge leaves a tree, so induction gives the edge count. For \(n=1\), the tree has zero edges, also \(n-1\). This gives a useful check on algorithm outputs.
Worked Networks
Worked Example: Connecting Five Sites
Five sites \(H,J,K,L,M\) have the following possible links and costs. The graph is defined by \(V=\{H,J,K,L,M\}\) and \(E=\{HJ,JK,KL,HM,LM\}\), with \(w(HJ)=2\), \(w(JK)=3\), \(w(KL)=4\), \(w(HM)=6\), and \(w(LM)=7\). Find a minimum-cost network that connects all five sites.
The edges are already in nondecreasing order. Begin with no selected links. Accept \(HJ\) at cost \(2\), joining \(H\) to \(J\). Accept \(JK\) at cost \(3\), joining \(K\) to that component. Accept \(KL\) at cost \(4\), adding \(L\). Accept \(HM\) at cost \(6\), adding \(M\) and connecting all five sites. When \(LM\), of cost \(7\), is considered, \(L\) and \(M\) are already connected by the selected path \(L-K-J-H-M\), so \(LM\) would create a cycle and is rejected.
The resulting links are \(HJ,JK,KL,HM\), and their total cost is \(2+3+4+6=15\). To check the minimum cost directly, consider any spanning tree. It must use at least one of the two links incident with \(M\), namely \(HM\) and \(LM\). If it uses exactly one, the other three links must connect \(H,J,K,L\). The only links among those four sites are \(HJ,JK,KL\), so all three are needed, costing \(2+3+4=9\). The link to \(M\) costs at least \(6\), giving a total of at least \(9+6=15\). If the tree uses both links to \(M\), they cost \(6+7=13\), and its two remaining links cost at least \(2+3=5\), so its total is at least \(13+5=18\). Thus every spanning tree costs at least \(15\), and the constructed tree attains that cost.
Worked Example: Rejecting a Cheaper Link That Closes a Cycle
Let \(V=\{A,B,C,D\}\) and \(E=\{AB,BC,AC,CD,DA\}\), with costs \(w(AB)=1\), \(w(BC)=2\), \(w(AC)=2\), \(w(CD)=3\), and \(w(DA)=4\). For equal costs, process \(BC\) before \(AC\). Run Kruskal’s algorithm.
First accept \(AB\), of cost \(1\). Next accept \(BC\), of cost \(2\); the selected path is now \(A-B-C\). The next edge, \(AC\), also costs \(2\), but its endpoints are already connected by \(A-B-C\), so reject it. Accept \(CD\), of cost \(3\), which adds \(D\). Finally reject \(DA\), of cost \(4\), because \(D\) and \(A\) are already connected.
The selected set is \(\{AB,BC,CD\}\). It connects all four vertices, has \(4-1=3\) edges, and has cost \(1+2+3=6\). As an independent check of the total, its three selected edge weights are \(1,2,3\), whose sum is \(6\). The rejected edge \(AC\) is inexpensive, but it adds no connectivity after \(AB\) and \(BC\) have been chosen.
Worked Example: Tied Costs and More Than One Minimum Tree
Let \(V=\{P,Q,R,S\}\) and \(E=\{PQ,QR,PR,RS,QS\}\), with \(w(PQ)=1\), \(w(QR)=1\), \(w(PR)=1\), \(w(RS)=2\), and \(w(QS)=2\). Process the three cost-\(1\) edges in the order \(PQ,QR,PR\), followed by \(RS,QS\).
Accept \(PQ\) and \(QR\), each of cost \(1\). Reject \(PR\): its endpoints are connected by \(P-Q-R\). Accept \(RS\), of cost \(2\), which adds \(S\). Reject \(QS\), because \(Q\) and \(S\) are now connected. The selected tree has cost \(1+1+2=4\), connects all four vertices, and has three edges.
The ties allow a different minimum tree. The set \(\{PQ,PR,RS\}\) connects all four vertices without a cycle and costs \(1+1+2=4\). Kruskal’s theorem guarantees that the algorithm’s result is minimum, while this second tree confirms that the minimum need not be unique.
Interpreting the Design and Avoiding Pitfalls
In the first network, a tempting but incorrect calculation is to purchase every available link, adding \(2+3+4+6+7=22\). That connects the sites, but it is not a minimum-cost design: link \(LM\) closes a cycle and raises the cost from \(15\) to \(22\) without improving connectivity. The correction is to test each link against the edges already selected, not to include every proposed link.
Rejecting a link in an MST model does not mean that the link is useless in every engineering design. It means only that the link is unnecessary for connectivity in the least-cost spanning tree under the model’s assumptions. A real network might deliberately include extra links for backup routes, resilience or capacity. Those requirements are not represented by the minimum spanning tree objective alone.
For a computed result, check three things: every site is included, the chosen links connect the sites without a cycle, and the total is the sum of the selected costs. A connected acyclic graph on \(n\) vertices has \(n-1\) edges, which is a helpful structural check. To justify that the total is least, use the theorem’s exchange argument or a separate lower-bound argument, as in the five-site example; merely choosing some cheap links does not establish optimality.
Check Your Understanding
Use the algorithm and its justification to answer these questions.
- For \(V=\{U,V,W\}\) and edges \(UV\) of cost \(2\), \(VW\) of cost \(5\), and \(UW\) of cost \(6\), which edge is rejected by Kruskal’s algorithm, and what is the MST cost?
- Why must a link rejected by Kruskal’s algorithm have endpoints already connected by the previously selected links?
- In the five-site example, explain why a spanning tree using both links incident with \(M\) costs at least \(18\).
- Does a rejected edge necessarily have a higher cost than every accepted edge? Explain using the tied-cost example.
- If the available-link graph is disconnected, can it have a spanning tree? State the reason in terms of connectivity.