Folioby Interconnected
Log InSign Up

Trees and Forests: The Minimal Connected Structures

We prove the equivalent characterizations of trees, establish the formula $|E|=|V|-1$, introduce rooted trees and Cayley's formula, and develop the theory of spanning trees and minimum spanning trees via Kruskal's and Prim's algorithms.

FO
Folio Official
March 1, 2026

1. Definition and Equivalent Characterizations

Definition 1 (Tree and forest).
A connected graph with no cycles is called a tree. A graph with no cycles (not necessarily connected) is called a forest. Equivalently, a forest is a graph each of whose connected components is a tree.
Theorem 2 (Equivalent characterizations of trees).
For a graph G on n vertices, the following are equivalent:
  1. G is a tree (connected and acyclic).

  2. There is exactly one path between every pair of vertices of G.

  3. G is connected and ∣E(G)∣=n−1.

  4. G is acyclic and ∣E(G)∣=n−1.

  5. G is connected and every edge is a bridge.

  6. G is acyclic, but the addition of any new edge creates a cycle.

Proof.
(1)⇒(2): Since G is connected, a path exists between any two vertices. If two or more paths existed between some pair, their union would contain a cycle, contradicting the assumption.

(2)⇒(3): The existence of paths implies connectivity. We prove ∣E∣=n−1 by induction on n. For n=1, we have ∣E∣=0=n−1. Suppose n≥2. A vertex of degree 1 (a leaf) must exist: if every vertex had degree at least 2, one could traverse edges from any starting vertex without immediate repetition, and finiteness would force a closed walk, hence a cycle, contradicting (2). Removing a leaf v and its incident edge yields a graph on n−1 vertices still satisfying (2). By induction, this graph has n−2 edges, so G has n−1.

(3)⇒(4): Suppose G is connected with ∣E∣=n−1 and contains a cycle. Removing one edge of the cycle preserves connectivity, producing a connected graph on n vertices with n−2 edges. But every connected graph satisfies ∣E∣≥n−1, a contradiction.

(4)⇒(1): Let the connected components of G be G1​,…,Gc​ with ∣V(Gi​)∣=ni​. Each Gi​ is a tree (connected and acyclic), so by (1)⇒(3) it has ni​−1 edges. Thus ∣E(G)∣=∑(ni​−1)=n−c. Since ∣E(G)∣=n−1, we get c=1, i.e., G is connected.

(1)⇒(5): Every edge of a tree is a bridge, for if an edge e lay on a cycle, the tree would contain a cycle — a contradiction.

(5)⇒(1): Connectivity is assumed. If a cycle existed, any edge e on that cycle would satisfy the property that G−e remains connected (the cycle provides an alternative route), so e would not be a bridge — a contradiction.

(1)⇒(6): Acyclicity is given. Adding a non-edge {u,v} creates a cycle together with the unique u-v path in the tree.

(6)⇒(1): Acyclicity is given. If G were disconnected, adding an edge between vertices in different components would not create a cycle, contradicting the hypothesis. □

2. Rooted Trees

Definition 3 (Rooted tree).
A rooted tree is a tree T in which a distinguished vertex r has been designated as the root. The unique path from r to each vertex induces a parent–child relation: if u lies on the path from r to v and {u,v}∈E(T), then u is the parent of v and v is a child of u. A vertex with no children is called a leaf.

r
a
b
c
d
e
f
g

3. Cayley's Formula

Theorem 4 (Cayley's formula).
The number of labeled trees on n labeled vertices {1,2,…,n} is nn−2.
Proof.
We give a proof via Prün vertices and sequences (a1​,…,an−2​) with each ai​∈{1,…,n}.

From tree to sequence. Given a tree T, repeat the following n−2 times: find the leaf with the smallest label, record the label of its unique neighbor as ai​, and remove the leaf.

From sequence to tree. Given a sequence (a1​,…,an−2​), reconstruct the tree as follows. Set S={1,…,n}. For i=1,…,n−2: let v be the smallest element of S that does not appear in (ai​,…,an−2​), add the edge {v,ai​}, and remove v from S. Finally, connect the two elements remaining in S by an edge.

One verifies that these two maps are mutual inverses, establishing a bijection. Since there are nn−2 possible sequences, the result follows. □
Example 5.
For n=3, we get 31=3. The three labeled trees on {1,2,3} have edge sets {{1,2},{1,3}}, {{1,2},{2,3}}, and {{1,3},{2,3}}.

4. Spanning Trees and Minimum Spanning Trees

Definition 6 (Spanning tree).
A spanning tree of a connected graph G is a subgraph of G that contains all vertices of G and is a tree.
Theorem 7.
Every connected graph has a spanning tree.
Proof.
If G is connected and acyclic, it is already a tree. Otherwise, G contains a cycle; removing any edge of this cycle preserves connectivity. Since the number of edges is finite, repeating this process eventually yields a tree. □
Definition 8 (Minimum spanning tree).
Given a connected graph G with edge weights w:E→R, a spanning tree T that minimizes w(T)=∑e∈E(T)​w(e) is called a minimum spanning tree (MST).
Theorem 9 (Cut property).
When all edge weights are distinct, the minimum-weight edge crossing any cut (i.e., any partition (S,V∖S)) belongs to every MST.
Proof.
Let e={u,v} (with u∈S, v∈V∖S) be the minimum-weight edge crossing the cut, and suppose e does not belong to some MST T. The unique u-v path in T crosses the cut an odd number of times, so it contains another edge f crossing the cut. The tree T−f+e is also a spanning tree, and w(e)<w(f) gives w(T−f+e)<w(T), contradicting the minimality of T. □

A weighted graph and its minimum spanning tree (thick edges, total weight 1+2+3+4=10):

1
2
4
3
5
6
a
b
c
d

Remark 10 (Kruskal's algorithm).
Sort the edges in nondecreasing order of weight and add each edge unless it creates a cycle. Using Union-Find, this runs in O(mlogm) time and correctly produces an MST. Kruskal's algorithm processes the graph above in the order {a,b} (weight 1), {b,c} (2), {c,d} (3), skipping {a,c} (4, creates cycle), {a,d} (5, creates cycle), {b,d} (6, creates cycle).
Algorithm 1: Kruskal's Algorithm
Input:
Connected graph G=(V,E), weight function w:E→R
Output:
Edge set T of a minimum spanning tree
T←∅ 
 Sort the edges by weight in nondecreasing order: e1​,e2​,…,em​ 
for all v∈V
MakeSet(v)
// Initialize Union-Find
end for
for i=1 to m
 Let ei​={u,v} 
if Find(u)=Find(v)
T←T∪{ei​} 
Union(u,v) 
end if
end for
return T
Remark 11 (Prim's algorithm).
Starting from a single vertex, repeatedly add the minimum-weight edge that connects the current tree to a vertex not yet in the tree. Using a priority queue, this runs in O(mlogn) time.
Algorithm 2: Prim's Algorithm
Input:
Connected graph G=(V,E), weight function w, starting vertex r
Output:
Edge set T of a minimum spanning tree
T←∅, S←{r} 
key[r]←0 
for all v∈V∖{r}
key[v]←+∞ 
end for
 Insert all vertices into priority queue Q with key values 
while Q=∅
u←ExtractMin(Q) 
S←S∪{u} 
if u=r
T←T∪{{u,parent[u]}} 
end if
for all (u,v)∈E with v∈Q
if w(u,v)<key[v]
key[v]←w(u,v) 
parent[v]←u 
DecreaseKey(Q,v,key[v]) 
end if
end for
end while
return T
Graph TheoryDiscrete MathematicsTextbookTreesSpanning TreesMinimum Spanning Trees
FO
Folio Official

Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.

1 followers·107 articles
Graph Theory TextbookPart 4 of 13
Previous
Paths and Connectivity
Next
Eulerian and Hamiltonian Graphs: Two Classical Traversal Problems

Share your expertise with the world

Write articles with LaTeX support, build your audience, and earn from your knowledge.

Start Writing — It's Free

More from Folio Official

Folio Official·March 1, 2026

Paths and Connectivity

We formalize the notions of walks, paths, and cycles, then develop the theory of connected components, vertex and edge connectivity, cut vertices and bridges, the characterization of bipartite graphs, and Menger's theorem.

Graph TheoryDiscrete MathematicsTextbook
3
Folio Official·March 1, 2026

Eulerian and Hamiltonian Graphs: Two Classical Traversal Problems

From the Bridges of Königsberg to Euler's theorem on Eulerian circuits, directed Eulerian graphs, Hamiltonian cycles, the theorems of Ore and Dirac, and the NP-completeness of the Hamiltonian cycle problem.

Graph TheoryDiscrete MathematicsTextbook
1
Folio Official·March 1, 2026

Network Flows

Flow networks, the max-flow min-cut theorem, the Ford--Fulkerson method, the Edmonds--Karp algorithm, Dinic's algorithm, and the reduction of bipartite matching to maximum flow.

Graph TheoryDiscrete MathematicsTextbook
Folio Official·March 1, 2026

Recurrence Relations and Counting: Solving Linear Recurrences

We present the method of characteristic equations for solving linear recurrences with constant coefficients, treat the case of repeated roots, discuss nonhomogeneous recurrences, establish the equivalence with generating functions, and introduce matrix exponentiation and the Kitamasa method.

CombinatoricsDiscrete MathematicsTextbook