DISCRETE MATH • GRAPH THEORY

Spanning trees and minimum spanning trees (intro)

Discover how spanning trees connect every vertex at minimal cost, powering network design from telecommunications to transportation.

Historical Context & Motivation

The study of spanning trees and minimum spanning trees arose from practical engineering problems that demanded efficient network connectivity. Long before formal graph theory existed, engineers and mathematicians grappled with the challenge of connecting a set of locations—cities, electrical stations, or telephone exchanges—using the least amount of material, cable, or road. The question seems deceptively simple: given a collection of points and the costs of linking them pairwise, how does one select a subset of connections that reaches every point while minimizing total cost? This question has driven some of the most elegant algorithms in combinatorial optimization and remains central to modern computer science and operations research.

1857
Cayley's Tree Enumeration
Arthur Cayley studied labeled trees and derived his famous formula, showing that the complete graph Kn has nn−2 distinct spanning trees. This laid foundational groundwork for structural graph theory.
1926
Borůvka's Algorithm
Czech mathematician Otakar Borůvka developed the first known algorithm for finding minimum spanning trees, motivated by the problem of designing an efficient electrical power network in Moravia.
1956
Kruskal's Algorithm
Joseph Kruskal published a greedy algorithm that builds a minimum spanning tree by repeatedly selecting the cheapest edge that does not form a cycle, providing an elegant and intuitive approach.
1957
Prim's Algorithm
Robert Prim independently rediscovered a method (originally due to Jarník in 1930) that grows a single tree by always attaching the nearest unvisited vertex, yielding efficient performance on dense graphs.
1995
Near-Linear Time MST
Karger, Klein, and Tarjan presented a randomized algorithm achieving expected O(|E|) time for minimum spanning trees, pushing the theoretical frontier toward optimality.

From Borůvka's original motivation of connecting Moravian towns with power lines to modern applications in clustering, image segmentation, and network routing, spanning trees serve as one of the most natural and useful substructures of a graph. The central question this lesson addresses is: what does it mean for a subgraph to span an entire graph while remaining acyclic, and how do we find such a structure with the smallest total edge weight?

Core Principles & Definitions

Before diving into algorithms and formulas, it is essential to establish the fundamental definitions and structural properties that govern spanning trees. Throughout this section, we consider a connected, undirected graph G = (V, E), where V is the vertex set and E is the edge set. A tree is a connected graph with no cycles, and a spanning subgraph of G is a subgraph that includes every vertex of G. Combining these two notions yields the concept of a spanning tree.

1

Spanning Tree

A subgraph T = (V, E') of G that is connected, acyclic, and includes all vertices of G. It uses exactly |V| − 1 edges.
2

Minimum Spanning Tree

Given a weight function w : E → ℝ, an MST is a spanning tree T whose total weight w(T) = Σ w(e) over all edges e ∈ T is minimized among all spanning trees of G.
3

Cut Property

For any cut (S, V\S) of G, the lightest edge crossing the cut must belong to some MST. This property is the theoretical backbone of greedy MST algorithms.
4

Cycle Property

For any cycle C in G, the heaviest edge in C (if unique) does not belong to any MST. This complements the cut property and justifies edge-deletion strategies.
5

Uniqueness Condition

If all edge weights are distinct, then G has exactly one unique MST. When weights repeat, multiple MSTs with the same total weight may exist.
KEY TAKEAWAY
Think of a spanning tree as the skeleton of a road network: it keeps every city reachable while using the fewest roads possible (exactly n − 1 roads for n cities). A minimum spanning tree goes further—it selects those n − 1 roads so that the total construction cost is as low as it can be. Just as a structural engineer seeks the lightest steel frame that still supports the building, an MST is the lightest connected substructure that still reaches every vertex.

Visual Explanation

The following diagram illustrates a weighted, connected graph on six vertices alongside one of its spanning trees. Observe how the spanning tree preserves all six vertices but selects only five edges—exactly |V| − 1—while remaining connected and acyclic. The edges highlighted in cyan form the minimum spanning tree, chosen because their combined weight is the smallest possible among all spanning trees of this graph.

Left: the original graph with 10 weighted edges. Right: the MST selects 5 edges (|V| − 1 = 6 − 1 = 5) with a total weight of 14. Notice that the heaviest edges (weight 7, 8, 9) are excluded—consistent with the cycle property.

In the diagram, vertex labels A through F are maintained in both views so you can trace correspondence. The original graph contains cycles—for instance, the triangle A–C–D–A formed by edges of weight 2, 3, and 7. By the cycle property, the heaviest edge in that cycle (weight 7) cannot appear in any MST. Similarly, edges of weight 8 and 9 are the heaviest in their respective cycles and are excluded. The MST retains only the lightest connections needed to keep every vertex reachable, and every vertex has degree ≥ 1 in T because T is connected.

Mathematical Framework

Several elegant results provide the mathematical backbone of spanning tree theory. We begin with the most basic structural fact: a tree on n vertices has exactly n − 1 edges. This is proven by induction—a single vertex is a tree with zero edges, and every tree on n ≥ 2 vertices has at least one leaf (vertex of degree 1); removing the leaf and its incident edge yields a tree on n − 1 vertices with n − 2 edges, completing the inductive step.

EDGE COUNT OF A TREE
|E(T)| = |V| − 1
For any tree T on vertex set V, the number of edges is exactly one fewer than the number of vertices. This is a necessary condition for a connected, acyclic graph.
CAYLEY'S FORMULA
τ(Kₙ) = n^(n−2)
The number of distinct labeled spanning trees of the complete graph Kn is nn−2. For K₅, this gives 5³ = 125 spanning trees. Can be proved via Prüfer sequences.
MST OBJECTIVE
w(T*) = min { Σ w(e) : e ∈ E(T) } over all spanning trees T of G
A minimum spanning tree T* minimizes the sum of edge weights over all spanning trees of G. When edge weights are distinct, T* is unique.
KIRCHHOFF'S MATRIX TREE THEOREM
τ(G) = any cofactor of L(G)
The total number of spanning trees τ(G) equals any cofactor of the Laplacian matrix L = D − A, where D is the degree matrix and A is the adjacency matrix. This provides a determinantal formula for counting spanning trees.

The cut property can be stated formally: if (S, V\S) is a partition of V into two non-empty sets and e is the unique minimum-weight edge with one endpoint in S and the other in V\S, then e belongs to every MST of G. Conversely, the cycle property asserts that if e is the unique maximum-weight edge on some cycle in G, then e is excluded from every MST. Together, these two properties provide the correctness proofs for all classical greedy MST algorithms.

Key MST Algorithms

Two algorithms dominate introductory treatments of minimum spanning trees: Kruskal's algorithm and Prim's algorithm. Both are greedy—they make locally optimal choices at each step—and both are guaranteed to produce a globally optimal MST. However, they differ in strategy: Kruskal's works edge-by-edge across the entire graph, while Prim's grows a single tree vertex-by-vertex.

Kruskal's algorithm (left, amber) processes edges globally in sorted order and uses a Union-Find data structure for cycle detection. Prim's algorithm (right, emerald) grows the tree from a single source, always attaching the nearest unvisited vertex via a priority queue. Both achieve O(|E| log |V|) time complexity with appropriate data structures.
Comparison of the two classic MST algorithms
PropertyKruskal's AlgorithmPrim's Algorithm
StrategyEdge-centric: sort edges globally, add greedilyVertex-centric: grow tree from a single source
Data StructureUnion-Find (disjoint set)Min-priority queue (binary or Fibonacci heap)
Time ComplexityO(|E| log |E|) ≈ O(|E| log |V|)O(|E| log |V|) binary heap; O(|E| + |V| log |V|) Fibonacci heap
Best ForSparse graphs (|E| ≈ |V|)Dense graphs (|E| ≈ |V|²)
Correctness BasisCut property applied across all componentsCut property applied to the growing tree's frontier

Worked Example — Kruskal's Algorithm

Consider a graph G with vertices {1, 2, 3, 4, 5} and the following weighted edges: (1,2) = 3, (1,3) = 7, (2,3) = 2, (2,4) = 5, (3,4) = 4, (3,5) = 6, (4,5) = 1. We will apply Kruskal's algorithm to find the MST.

Finding the MST via Kruskal's Algorithm
1
Step 1 — Sort Edges by WeightArrange all edges in non-decreasing order of weight: (4,5) = 1, (2,3) = 2, (1,2) = 3, (3,4) = 4, (2,4) = 5, (3,5) = 6, (1,3) = 7. We have |E| = 7 edges and need |V| − 1 = 4 edges for the MST.
Sorted edge list: 1, 2, 3, 4, 5, 6, 7
2
Step 2 — Add Edge (4,5), Weight 1Vertices 4 and 5 are in separate components. Adding this edge does not create a cycle. Initialize Union-Find: merge sets {4} and {5} into {4, 5}.
MST edges so far: {(4,5)}. Total weight: 1.
3
Step 3 — Add Edge (2,3), Weight 2Vertices 2 and 3 are each in singleton components. Adding this edge is safe. Merge {2} and {3} into {2, 3}.
MST edges: {(4,5), (2,3)}. Total weight: 3.
4
Step 4 — Add Edge (1,2), Weight 3Vertex 1 is in {1} and vertex 2 is in {2, 3}. Different components, so no cycle. Merge into {1, 2, 3}.
MST edges: {(4,5), (2,3), (1,2)}. Total weight: 6.
5
Step 5 — Add Edge (3,4), Weight 4Vertex 3 is in {1, 2, 3} and vertex 4 is in {4, 5}. These are different components, so adding this edge connects all vertices into a single component. We now have 4 edges, which equals |V| − 1, so the algorithm terminates.
MST = {(4,5), (2,3), (1,2), (3,4)}. Total weight = 1 + 2 + 3 + 4 = 10.
6
Step 6 — VerifyThe resulting subgraph has 5 vertices and 4 edges (= |V| − 1), is connected (every vertex is reachable from every other), and is acyclic (no cycle exists among the 4 selected edges). The remaining edges (2,4) = 5, (3,5) = 6, and (1,3) = 7 would each create a cycle if added, confirming they are correctly excluded.
The MST is valid with minimum total weight 10.

Strengths, Limitations & Practical Considerations

Spanning trees and MSTs are powerful abstractions, but they come with trade-offs that practitioners must understand. An MST optimizes for total edge weight, but it does not optimize for other objectives such as maximum individual edge weight, path length between specific pairs, or fault tolerance. Understanding these limitations is crucial for selecting the right tool in network design.

Strengths and limitations of MST-based network design
StrengthsLimitations
Polynomial-time solvable; efficient O(|E| log |V|) algorithms existNo redundancy: removing any edge disconnects the tree (single point of failure)
Greedy algorithms yield globally optimal solutions (rare in optimization)Does not minimize maximum edge weight (that's the bottleneck spanning tree problem)
Foundation for approximation algorithms (e.g., TSP 2-approximation)Does not account for capacity constraints or flow requirements
Applicable to any connected, undirected, weighted graphDirected graphs require minimum spanning arborescences (Edmonds' algorithm), a harder problem
Unique when all edge weights are distinct, ensuring determinismNon-unique when weights repeat, requiring tie-breaking conventions
PRACTICAL INSIGHT
An MST is like the cheapest possible electrical wiring that connects every room in a building to the power source—but if any single wire breaks, some room goes dark. In practice, telecommunications companies often augment the MST with a few extra edges to create 2-edge-connected subgraphs for fault tolerance, trading a small cost increase for significantly improved reliability.

Connections to Advanced Topics

The MST is not an isolated topic; it connects deeply to several branches of combinatorics, optimization, and algorithm design. Understanding these connections positions you to appreciate why spanning trees appear as subroutines or structural motifs in far more complex problems.

From introductory MST concepts to advanced theory
Introductory ConceptAdvanced Extension
MST of an undirected graphMinimum spanning arborescence (directed MST) via Edmonds/Chu-Liu algorithm
Kruskal's greedy approachMatroid theory: MSTs are optimal bases in the graphic matroid, generalizing greedy optimality
Counting spanning trees (Cayley, Kirchhoff)Algebraic graph theory and spectral methods; connections to random walks and electrical networks
MST as cheapest connected subgraphSteiner tree problem (NP-hard): connect a subset of vertices at minimum cost
MST-based TSP approximationChristofides' algorithm gives a 3/2-approximation for metric TSP using MST + minimum matching

Perhaps the most profound connection is to matroid theory. A graphic matroid M(G) has the edge set E as its ground set and the acyclic subsets (forests) as its independent sets. The spanning trees of G are precisely the bases of M(G). The greedy algorithm for matroids—selecting the cheapest element that maintains independence—reduces to Kruskal's algorithm in this setting, providing a deep theoretical explanation for why the greedy approach works. This is one of the few optimization settings where greedy is provably optimal, a fact that generalizes far beyond graph theory into combinatorial optimization.

Practice Problems

PROBLEM 1CONCEPTUAL
A connected graph G has 8 vertices and 15 edges. How many edges does any spanning tree of G have? Explain why adding any edge from G to one of its spanning trees must create exactly one cycle.
PROBLEM 2BASIC CALCULATION
Use Cayley's formula to determine how many distinct labeled spanning trees exist for the complete graph K₆. Then verify that the formula gives the correct answer for K₃ (which you can enumerate by hand).
PROBLEM 3INTERMEDIATE
Consider a graph on vertices {A, B, C, D, E} with edges: (A,B) = 6, (A,C) = 1, (A,D) = 5, (B,C) = 4, (B,D) = 2, (C,D) = 3, (C,E) = 8, (D,E) = 7. Apply Kruskal's algorithm step by step and state the MST edges and total weight.
PROBLEM 4APPLIED
A telecommunications company needs to connect 5 data centers with fiber optic cable. The costs (in millions of dollars) for each potential link are: DC1–DC2: 12, DC1–DC3: 8, DC1–DC4: 15, DC2–DC3: 10, DC2–DC5: 7, DC3–DC4: 6, DC3–DC5: 14, DC4–DC5: 9. Find the minimum total cost to connect all data centers and identify which links should be built.
PROBLEM 5CRITICAL THINKING
Prove or disprove: if G is a connected graph where all edge weights are distinct, then for every edge e in the MST T*, there exists a cut (S, V\S) such that e is the unique lightest edge crossing that cut. (Hint: consider removing e from T* and examine the resulting components.)

Summary

A spanning tree of a connected graph G = (V, E) is a connected, acyclic subgraph that includes every vertex and uses exactly |V| − 1 edges. A minimum spanning tree (MST) is the spanning tree whose total edge weight is minimized. The cut property guarantees that the lightest edge crossing any cut belongs to some MST, while the cycle property ensures the heaviest edge in any cycle is excluded. Cayley's formula tells us that Kn has nn−2 labeled spanning trees.

Two classical greedy algorithms construct MSTs efficiently: Kruskal's algorithm sorts edges globally and adds them if no cycle forms (using Union-Find), running in O(|E| log |E|) time. Prim's algorithm grows a tree from a source vertex via a priority queue, running in O(|E| log |V|) with a binary heap. When all edge weights are distinct, the MST is unique. MSTs underpin applications in network design, clustering, and serve as subroutines in approximation algorithms such as the TSP 2-approximation and connect to deep theory including matroid theory and algebraic graph theory.

Varsity Tutors • Discrete Math • Spanning trees and minimum spanning trees (intro)