1 Definition and Equivalent Characterizations
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.
For a graph G on n vertices, the following are equivalent:
G is a tree (connected and acyclic).
There is exactly one path between every pair of vertices of G.
G is connected and ∣E(G)∣=n−1.
G is acyclic and ∣E(G)∣=n−1.
G is connected and every edge is a bridge.
G is acyclic, but the addition of any new edge creates a cycle.
(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
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.
3 Cayley's Formula
The number of labeled trees on n labeled vertices {1,2,…,n} is nn−2.
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. □
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
A spanning tree of a connected graph G is a subgraph of G that contains all vertices of G and is a tree.
Every connected graph has a spanning tree.
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. □
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).
When all edge weights are distinct, the minimum-weight edge crossing any cut (i.e., any partition (S,V∖S)) belongs to every MST.
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. □
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)
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
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