Skip to content

Chapter 30. Spanning Trees

A spanning tree is a tree that contains every vertex of a connected graph.

It keeps the vertex set of the graph but selects only enough edges to preserve connectivity. In this sense, a spanning tree is a cycle-free skeleton of a connected graph. It removes redundancy while keeping all vertices reachable.

Spanning trees are central in graph theory because they connect trees with general connected graphs. They are also central in algorithms, where one often wants a minimal connected structure inside a larger network.

30.1 Definition

Let

G=(V,E) G = (V,E)

be a connected undirected graph.

A spanning tree of GG is a subgraph

T=(V,ET) T = (V,E_T)

such that

ETE E_T \subseteq E

and TT is a tree.

The word spanning means that TT contains all vertices of GG. Only the edge set is reduced.

If GG has nn vertices, then every spanning tree of GG has exactly

n1 n-1

edges.

30.2 Example

Consider the graph

V={1,2,3,4} V=\{1,2,3,4\}

with edge set

E={{1,2},{2,3},{3,4},{4,1},{1,3}}. E= \{ \{1,2\}, \{2,3\}, \{3,4\}, \{4,1\}, \{1,3\} \}.

This graph is connected and contains cycles.

One spanning tree is obtained by choosing

ET={{1,2},{2,3},{3,4}}. E_T= \{ \{1,2\}, \{2,3\}, \{3,4\} \}.

The resulting subgraph contains all four vertices and has no cycle. It is a path on four vertices, so it is a tree.

Another spanning tree is

ET={{1,3},{1,4},{2,3}}. E_T= \{ \{1,3\}, \{1,4\}, \{2,3\} \}.

A connected graph may have many different spanning trees.

30.3 Existence of Spanning Trees

Every finite connected graph has a spanning tree.

Theorem 30.1

If GG is a finite connected graph, then GG has a spanning tree.

Proof

If GG contains no cycle, then GG is already a tree. Since it is connected and contains all its vertices, it is a spanning tree of itself.

Suppose GG contains a cycle. Choose one edge from the cycle and remove it. The graph remains connected, because the two endpoints of the removed edge are still connected by the rest of the cycle.

If the resulting graph still contains a cycle, repeat the process.

Since GG is finite, this process must stop. The final graph is connected and acyclic. Therefore it is a tree. Since no vertices were removed, it is a spanning tree of GG.

30.4 Spanning Trees as Minimal Connected Subgraphs

A spanning tree is a minimal connected spanning subgraph.

This means that it connects all vertices, and removing any edge destroys that connectivity.

Theorem 30.2

Let TT be a spanning tree of a connected graph GG. Then removing any edge from TT disconnects TT.

Proof

Since TT is a tree, every edge of TT is a bridge. Removing any edge from a tree disconnects it.

Thus a spanning tree contains no unnecessary edge for connectivity.

The theorem also explains why spanning trees are used as minimal network designs. Every selected edge is needed.

30.5 Spanning Trees and Cycles

A spanning tree removes exactly enough edges to eliminate all cycles.

Let GG be a connected graph with nn vertices and mm edges. A spanning tree has n1n-1 edges. Therefore one must remove

m(n1) m-(n-1)

edges from GG to obtain a spanning tree.

The number

mn+1 m-n+1

is called the cycle rank, cyclomatic number, or circuit rank of a connected graph.

It measures the number of independent cycles in the graph.

30.6 Characterization by Edge Count

A connected spanning subgraph is a spanning tree exactly when it has the smallest possible number of edges.

Theorem 30.3

Let GG be a connected graph with nn vertices. If HH is a connected spanning subgraph of GG, then

E(H)n1. |E(H)| \geq n-1.

Equality holds if and only if HH is a spanning tree.

Proof

Since HH is connected and has nn vertices, it contains a spanning tree. Every spanning tree on nn vertices has n1n-1 edges. Therefore

E(H)n1. |E(H)| \geq n-1.

If equality holds, then HH has exactly n1n-1 edges. A connected graph with n1n-1 edges is a tree. Hence HH is a spanning tree.

Conversely, if HH is a spanning tree, then it has exactly n1n-1 edges.

30.7 Building Spanning Trees by Search

Graph traversal algorithms naturally produce spanning trees.

Breadth-First Search Tree

If breadth-first search starts at a vertex ss in a connected graph, then each newly discovered vertex records the edge by which it was first reached.

These discovery edges form a spanning tree called a BFS tree.

A BFS tree has an additional distance property. For every vertex vv, the distance from ss to vv in the BFS tree equals the shortest-path distance from ss to vv in the original unweighted graph.

Depth-First Search Tree

Depth-first search also records discovery edges. These edges form a DFS tree.

A DFS tree records the recursive exploration structure of the graph. It is useful for detecting cycles, finding articulation points, computing connected components, and constructing topological orderings in directed graphs.

Both BFS and DFS show that spanning trees are constructive objects. They can be built systematically.

30.8 Spanning Forests in Disconnected Graphs

A disconnected graph has no spanning tree, because no connected subgraph can contain all vertices.

Instead, one uses a spanning forest.

A spanning forest contains every vertex and includes one spanning tree for each connected component.

If a graph has connected components

G1,G2,,Gk, G_1,G_2,\ldots,G_k,

then a spanning forest consists of spanning trees

T1,T2,,Tk, T_1,T_2,\ldots,T_k,

where TiT_i spans GiG_i.

If the graph has nn vertices and kk components, then every spanning forest has

nk n-k

edges.

30.9 Counting Spanning Trees

A connected graph may have many spanning trees.

For the complete graph KnK_n, Cayley’s formula gives the number of spanning trees:

nn2. n^{n-2}.

For example:

GraphNumber of spanning trees
K2K_211
K3K_333
K4K_41616
K5K_5125125

More generally, the number of spanning trees of a graph can be computed using the Matrix-Tree Theorem, which uses the graph Laplacian.

This connects spanning trees with linear algebra and spectral graph theory.

30.10 Edge Exchange Property

Spanning trees satisfy an important exchange principle.

Theorem 30.4

Let TT be a spanning tree of a connected graph GG, and let ee be an edge of GG not in TT. Then T+eT+e contains exactly one cycle. If ff is any edge on that cycle, then

T+ef T+e-f

is a spanning tree, provided ff lies on the cycle.

Proof

Since TT is a tree, adding the edge ee creates exactly one cycle.

If an edge ff on this cycle is removed, the cycle is broken. The graph remains connected, because the endpoints formerly joined through ff are still connected by the rest of the cycle.

The resulting graph is connected, spans all vertices, and has n1n-1 edges. Therefore it is a spanning tree.

This exchange property is fundamental in the theory of graphic matroids and minimum spanning tree algorithms.

30.11 Minimum Spanning Trees

If the edges of GG have weights, then a natural problem is to find a spanning tree of minimum total weight.

Let

w:ER w:E \to \mathbb{R}

assign a weight to each edge.

The weight of a spanning tree TT is

w(T)=eE(T)w(e). w(T)=\sum_{e\in E(T)}w(e).

A minimum spanning tree is a spanning tree TT such that

w(T)w(T) w(T) \leq w(T')

for every spanning tree TT' of GG.

Minimum spanning trees are used in network design, clustering, circuit layout, approximation algorithms, and image segmentation.

The next chapter studies them in detail.

30.12 Applications

Spanning trees appear whenever a connected structure must be reduced to a minimal connected backbone.

ApplicationRole of spanning tree
Communication networkConnect all nodes with minimal links
Electrical networkAnalyze independent branches
RoutingBuild loop-free forwarding structure
ClusteringRemove high-weight edges from an MST
Distributed systemsBroadcast over a tree topology
Graph algorithmsOrganize traversal and recursion
Approximation algorithmsUse tree structure as a simplified model

The main advantage is structural simplicity. A spanning tree preserves reachability but removes all cycles.

30.13 Summary

A spanning tree of a connected graph is a tree that contains every vertex of the graph.

Every finite connected graph has at least one spanning tree. If the graph has nn vertices, each spanning tree has exactly n1n-1 edges.

Spanning trees are minimal connected spanning subgraphs. Removing any selected edge disconnects them. Adding any unused edge creates exactly one cycle.

They form a bridge between general graphs and trees. This makes them useful both theoretically and algorithmically, especially in traversal, optimization, network design, and graph decomposition.