A minimum spanning tree is a spanning tree of least total edge weight.
The setting is a connected undirected graph whose edges have weights. The graph may describe a road system, a communication network, a circuit, a clustering problem, or any structure where connecting vertices has a cost. A spanning tree connects all vertices without cycles. A minimum spanning tree chooses such a tree with minimum total cost.
Minimum spanning trees are among the basic examples of greedy methods in graph algorithms. Kruskal’s algorithm and Prim’s algorithm both build a minimum spanning tree by repeatedly choosing locally cheapest safe edges. Their correctness depends on the cut property and the cycle property.
31.1 Weighted Graphs
Let
be a connected undirected graph. A weight function is a function
For an edge
the value
is called the weight, cost, or length of .
If is a spanning tree of , then the weight of is
The goal is to find a spanning tree whose total weight is as small as possible.
31.2 Definition
Let be a connected weighted graph.
A minimum spanning tree of is a spanning tree such that
for every spanning tree of .
The abbreviation MST is commonly used for minimum spanning tree.
If has vertices, every spanning tree has exactly
edges. Thus an MST minimizes the sum of weights among all connected, acyclic, spanning subgraphs.
31.3 Example
Consider the weighted graph with vertices
and weighted edges:
| Edge | Weight |
|---|---|
One spanning tree is
with total weight
Another spanning tree is
with total weight
The second tree has smaller total weight. In fact, it is a minimum spanning tree.
31.4 Existence
Every finite connected weighted graph has at least one minimum spanning tree.
This follows from two facts. First, every finite connected graph has at least one spanning tree. Second, a finite graph has only finitely many spanning trees. Therefore the set of possible spanning tree weights is finite and has a minimum element.
If the graph is disconnected, no spanning tree exists. In that case one may instead seek a minimum spanning forest, consisting of one minimum spanning tree in each connected component.
31.5 Uniqueness
A graph may have more than one minimum spanning tree.
For example, if all edge weights are equal, then every spanning tree is a minimum spanning tree.
However, distinct edge weights guarantee uniqueness.
Theorem 31.1
If all edge weights in a connected graph are distinct, then the graph has a unique minimum spanning tree.
Proof
Suppose, for contradiction, that there are two different minimum spanning trees and .
Choose the edge
of smallest weight among all edges that belong to exactly one of the two trees.
Add to . Since is a tree, this creates exactly one cycle. That cycle contains . Since has no cycle, the cycle must contain some edge
By the choice of and the distinctness of edge weights,
Remove from . The result is another spanning tree, but its total weight is smaller than . This contradicts the assumption that was minimum.
Therefore the minimum spanning tree is unique.
31.6 The Cut Property
A cut partitions the vertex set into two nonempty parts:
An edge crosses the cut if one endpoint lies in and the other endpoint lies in .
The cut property says that a lightest edge crossing a cut is safe to use in a minimum spanning tree. In the strict form, if the lightest edge across the cut is unique, then it belongs to every MST.
Theorem 31.2
Let be a connected weighted graph. Let be a unique minimum-weight edge crossing some cut. Then every minimum spanning tree of contains .
Proof
Let the cut be
Suppose an MST does not contain . Add to . This creates exactly one cycle.
The edge crosses the cut, so the cycle must cross the cut again at some other edge . Since is the unique minimum-weight edge crossing the cut,
Remove . The graph remains connected and spanning, and it has the same number of edges as a tree. Hence it is a spanning tree. Its weight is smaller than , contradicting the minimality of .
Therefore every MST contains .
31.7 The Cycle Property
The cycle property gives the dual rule.
If an edge is strictly heavier than every other edge on a cycle, then it cannot belong to any minimum spanning tree.
Theorem 31.3
Let be a cycle in a connected weighted graph. If is the unique maximum-weight edge on , then no minimum spanning tree contains .
Proof
Suppose an MST contains .
Remove from . The tree splits into two connected components. Since was a cycle, there is another edge on connecting these two components.
Because is the unique maximum-weight edge on ,
Add to . The result is a spanning tree of smaller total weight. This contradicts the assumption that was minimum.
Therefore belongs to no MST.
31.8 Kruskal’s Algorithm
Kruskal’s algorithm builds an MST by considering edges in increasing order of weight.
It starts with no edges. At each step, it adds the next lightest edge that does not create a cycle.
Algorithm
Input: a connected weighted graph .
- Sort the edges by nondecreasing weight.
- Start with the empty set
For each edge , in sorted order:
- If adding to does not create a cycle, add .
- Otherwise, discard .
Stop when has
edges.
The graph
is a minimum spanning tree.
Kruskal’s algorithm is usually implemented with a disjoint-set data structure. The disjoint-set structure tracks which connected component each vertex currently belongs to. An edge is accepted exactly when its endpoints lie in different components.
31.9 Correctness of Kruskal’s Algorithm
The correctness of Kruskal’s algorithm follows from the cut property.
At any step, the accepted edges form a forest. Suppose Kruskal’s algorithm considers an edge
and accepts it. Then and lie in different components of the current forest.
Let be the vertex set of the component containing . The edge crosses the cut
Since the algorithm considers edges in increasing order, no lighter edge crossing this cut is available without already having been considered. Any lighter crossing edge would have joined two different components and would have been accepted earlier.
Thus is a lightest safe edge across a cut. By the cut property, it can be included in some minimum spanning tree.
Repeating this argument for each accepted edge shows that all accepted edges can be extended to an MST. When the algorithm has accepted edges, it has a spanning tree, and that tree is minimum.
31.10 Prim’s Algorithm
Prim’s algorithm grows one tree outward from a starting vertex.
It starts with a single vertex. At each step, it adds the lightest edge connecting the current tree to a vertex outside the tree.
Algorithm
Input: a connected weighted graph .
- Choose a starting vertex .
- Set
- Repeatedly choose a minimum-weight edge crossing the cut
- Add the chosen edge and its outside endpoint to the tree.
- Stop when
The selected edges form a minimum spanning tree.
Prim’s algorithm is usually implemented with a priority queue, where each outside vertex is keyed by the cheapest edge currently connecting it to the growing tree.
31.11 Correctness of Prim’s Algorithm
Prim’s algorithm is a direct application of the cut property.
At every step, the current set contains the vertices already included in the growing tree. The algorithm chooses a lightest edge crossing the cut
By the cut property, such an edge is safe. Adding it preserves the possibility of completing the selected edges to an MST.
After edge additions, all vertices have been included. The selected edges form a spanning tree. Since every selected edge was safe, the resulting spanning tree is minimum.
31.12 Kruskal Compared with Prim
Kruskal’s algorithm and Prim’s algorithm solve the same problem by different growth patterns.
| Feature | Kruskal’s algorithm | Prim’s algorithm |
|---|---|---|
| Growth pattern | Builds a forest | Builds one tree |
| Main choice | Lightest edge avoiding cycles | Lightest edge leaving current tree |
| Data structure | Disjoint-set union | Priority queue |
| Natural for | Sparse edge lists | Adjacency lists with heaps |
| Correctness principle | Cut property | Cut property |
Kruskal’s algorithm is global: it looks at all edges in increasing order. Prim’s algorithm is local: it expands from the current tree boundary.
31.13 Time Complexity
Let
With sorting and disjoint-set union, Kruskal’s algorithm runs in
Since
in a simple graph, this is also commonly written as
Prim’s algorithm depends on the representation and priority queue. With adjacency lists and a binary heap, it runs in
With a Fibonacci heap, the theoretical bound is
In practice, simpler priority queues are often preferred unless the graph size and density justify the more complex implementation.
31.14 Negative Edge Weights
Minimum spanning tree algorithms allow negative edge weights.
This differs from some shortest-path algorithms, where negative weights may cause difficulty. For MSTs, only the relative order of edges matters. Kruskal’s and Prim’s algorithms still work when weights are negative, zero, or positive.
A negative edge is simply attractive to include, provided it does not violate the tree structure.
31.15 Minimum Bottleneck Spanning Trees
The bottleneck of a spanning tree is the maximum edge weight in the tree.
A minimum bottleneck spanning tree minimizes this maximum edge weight.
Every minimum spanning tree is a minimum bottleneck spanning tree. However, a minimum bottleneck spanning tree need not be a minimum spanning tree.
The distinction is important. MST minimizes total cost. Bottleneck optimization minimizes the worst selected edge.
31.16 Applications
Minimum spanning trees appear in many settings where a network must connect all sites at low cost.
| Application | Interpretation |
|---|---|
| Network design | Connect all locations with minimum total link cost |
| Clustering | Remove large MST edges to form clusters |
| Image segmentation | Group pixels or regions by similarity |
| Approximation algorithms | Build low-cost structures for harder problems |
| Circuit design | Connect terminals with short total wiring |
| Taxonomy | Build similarity-based hierarchical structure |
In each case, the MST gives a sparse global connection pattern.
31.17 Limitations
A minimum spanning tree minimizes total edge weight, but it does not necessarily minimize distances between pairs of vertices.
For example, replacing a dense network by an MST may make some routes much longer. An MST has no redundant paths, so it is fragile: removing any edge disconnects it.
Thus MSTs are appropriate when low total connection cost is the main objective. They are less appropriate when redundancy, fault tolerance, low latency, or high capacity are required.
31.18 Summary
A minimum spanning tree is a spanning tree with minimum total edge weight.
The two main structural principles are the cut property and the cycle property. The cut property identifies safe edges. The cycle property identifies edges that cannot be part of an MST.
Kruskal’s algorithm builds an MST by adding lightest cycle-free edges. Prim’s algorithm builds an MST by repeatedly adding the lightest edge leaving the current tree.
Both algorithms are greedy. Their correctness comes from the structure of cuts and cycles in weighted graphs.