Skip to content

Chapter 10. Trees

A tree is a connected graph with no cycles. Trees are among the most important structures in graph theory because they combine two properties that strongly constrain structure:

  1. Every pair of vertices is connected.
  2. No closed path exists.

These conditions make trees sparse, hierarchical, and easy to analyze. Trees appear in algorithms, file systems, parsing, routing, optimization, databases, compilers, phylogenetics, and many other areas.

10.1 Definition of a Tree

A tree is a connected acyclic graph.

Equivalently, a graph TT is a tree when:

  1. TT is connected.
  2. TT contains no cycle.

For example, the graph with vertex set

V={a,b,c,d,e} V=\{a,b,c,d,e\}

and edge set

E={{a,b},{a,c},{c,d},{c,e}} E= \{\{a,b\},\{a,c\},\{c,d\},\{c,e\}\}

is a tree.

The graph is connected because every pair of vertices is joined by a path. It is acyclic because no cycle exists.

Trees form the basic connected structures without redundancy.

10.2 Forests

A forest is an acyclic graph.

Thus every connected component of a forest is a tree.

A forest may be disconnected. A tree is exactly a connected forest.

For example, the graph

E={{a,b},{b,c},{d,e}} E= \{\{a,b\},\{b,c\},\{d,e\}\}

is a forest with two components:

{a,b,c} \{a,b,c\}

and

{d,e}. \{d,e\}.

Each component is a tree.

10.3 Basic Examples

Several standard graph families are trees.

GraphTree?Reason
Path graph PnP_nYesConnected and acyclic
Cycle graph CnC_nNoContains a cycle
Complete graph KnK_n, n3n \geq 3NoContains cycles
Star graphYesConnected and acyclic
Empty graph on one vertexYesConnected and acyclic

The simplest nontrivial tree is

P2, P_2,

a graph with two vertices and one edge.

10.4 Unique Path Property

One of the central properties of trees is uniqueness of paths.

Theorem

A graph TT is a tree if and only if every pair of distinct vertices is joined by exactly one path.

Proof

Suppose TT is a tree.

Because TT is connected, at least one path joins every pair of vertices.

Suppose two distinct paths joined vertices uu and vv. Traversing one path from uu to vv and returning along the other would create a cycle. This contradicts acyclicity.

Therefore exactly one path joins every pair of vertices.

Conversely, suppose every pair of vertices is joined by exactly one path.

Then the graph is connected.

If a cycle existed, then two distinct paths would connect some pair of vertices on the cycle. This contradicts uniqueness.

Hence the graph is acyclic and therefore a tree.

This theorem characterizes trees through path structure rather than directly through cycles.

10.5 Trees Have Few Edges

Trees are sparse graphs.

Theorem

If a tree TT has nn vertices, then it has exactly

n1 n-1

edges.

Proof

The proof proceeds by induction on nn.

If

n=1, n=1,

then the tree consists of one vertex and no edges, so the formula holds.

Assume every tree with n1n-1 vertices has n2n-2 edges.

Let TT be a tree with nn vertices. Since TT is finite and acyclic, it contains a leaf. Remove a leaf vv and its incident edge.

The remaining graph is still a tree. It has

n1 n-1

vertices, so by induction it has

n2 n-2

edges.

Restoring the removed edge gives

n1 n-1

edges in total.

Thus every tree with nn vertices has exactly

n1 n-1

edges.

This formula is one of the defining numerical properties of trees.

10.6 Leaves

A leaf is a vertex of degree 11.

Leaves occur naturally at the outer boundary of a tree.

Theorem

Every tree with at least two vertices has at least two leaves.

Proof

Let

v0,v1,,vk v_0,v_1,\ldots,v_k

be a longest path in the tree.

Suppose v0v_0 had degree greater than 11. Then some edge from v0v_0 would lead to a vertex not already on the path. Extending the path through that edge would produce a longer path, contradicting maximality.

Therefore

deg(v0)=1. \deg(v_0)=1.

Similarly,

deg(vk)=1. \deg(v_k)=1.

Thus both endpoints are leaves.

This theorem shows that trees always branch outward toward degree-11 vertices.

10.7 Equivalent Characterizations of Trees

Several different properties characterize trees.

Theorem

For a finite graph TT with nn vertices, the following are equivalent:

  1. TT is a tree.
  2. TT is connected and has n1n-1 edges.
  3. TT is acyclic and has n1n-1 edges.
  4. Every pair of vertices is joined by exactly one path.
  5. TT is connected, and removing any edge disconnects it.
  6. TT is acyclic, and adding any new edge creates exactly one cycle.

These equivalent forms are fundamental in graph theory. Different proofs and algorithms naturally use different characterizations.

10.8 Minimal Connected Graphs

Trees are minimal connected graphs.

If any edge is removed from a tree, the graph becomes disconnected.

Proof

Let

e={u,v} e=\{u,v\}

be an edge of a tree TT.

Since TT has exactly one path between any two vertices, the edge ee lies on the unique path between uu and vv.

Removing ee destroys that path. Therefore uu and vv become disconnected.

Hence every edge of a tree is a bridge.

This property shows that trees contain no redundant edges.

10.9 Maximal Acyclic Graphs

Trees are maximal acyclic graphs.

If an edge is added between two nonadjacent vertices of a tree, exactly one cycle is created.

Proof

Let uu and vv be nonadjacent vertices of a tree TT.

Because TT is connected, a unique path joins uu and vv.

Adding the edge

{u,v} \{u,v\}

creates a closed walk consisting of that path plus the new edge.

This produces exactly one cycle, because no cycle existed previously.

Thus trees are acyclic graphs that become cyclic immediately when any extra edge is added.

10.10 Rooted Trees

A rooted tree is a tree with one distinguished vertex called the root.

The root introduces hierarchy and direction.

If rr is the root, then every vertex except rr has a unique parent: the previous vertex on the unique path from rr.

Vertices connected downward from a vertex are called its children.

For example:

        r
      / | \
     a  b  c
        |
        d

Here:

  • rr is the root.
  • a,b,ca,b,c are children of rr.
  • dd is a child of bb.

Rooted trees appear in syntax trees, file systems, heaps, search trees, and recursive structures.

10.11 Parent, Child, and Sibling Relations

In a rooted tree:

  • The parent of vv is the preceding vertex on the path from the root.
  • A child of uu is a vertex whose parent is uu.
  • Vertices with the same parent are siblings.

These relations convert the tree into a hierarchical structure.

If

u u

is above

v v

on the root path, then uu is an ancestor of vv, and vv is a descendant of uu.

10.12 Levels and Height

The level or depth of a vertex is its distance from the root.

The root has depth 00.

The height of a rooted tree is the maximum depth of any vertex.

For example:

        r
       / \
      a   b
         / \
        c   d

The depths are:

VertexDepth
rr0
aa1
bb1
cc2
dd2

The tree height is 22.

Tree height measures the longest root-to-vertex path.

10.13 Binary Trees

A binary tree is a rooted tree in which every vertex has at most two children.

The children are often distinguished as left and right children.

Binary trees are central in computer science because they support recursive decomposition and efficient search structures.

Examples include:

StructureDescription
Binary search treeOrdered search structure
HeapPriority queue structure
Expression treeArithmetic expression representation
Huffman treePrefix coding structure

A full binary tree is a binary tree in which every internal vertex has exactly two children.

10.14 Spanning Trees

Let

G G

be a connected graph.

A spanning tree of GG is a subgraph of GG that:

  1. Contains every vertex of GG.
  2. Is a tree.

A spanning tree preserves connectivity while removing cycles.

For example, if GG is a cycle graph

C4, C_4,

then removing any one edge produces a spanning tree.

Every connected graph has at least one spanning tree.

10.15 Constructing Spanning Trees

A spanning tree can be constructed by repeatedly removing edges from cycles while preserving connectivity.

Alternatively, breadth-first search and depth-first search naturally generate spanning trees.

A BFS spanning tree records shortest-path structure from the starting vertex.

A DFS spanning tree records recursive exploration structure.

Spanning trees are fundamental in routing, network design, optimization, and graph algorithms.

10.16 Cayley’s Formula

The number of distinct labeled trees on nn vertices is

nn2. n^{n-2}.

This result is called Cayley’s formula.

For example:

nnNumber of labeled trees
11
21
33
416
5125

Cayley’s formula is one of the classical counting results in combinatorics. It shows that even though trees are sparse, the number of possible tree structures grows rapidly. (en.wikipedia.org)

10.17 Tree Traversals

Traversal algorithms systematically visit the vertices of a tree.

Common traversals include:

TraversalStrategy
PreorderVisit node before children
InorderVisit left subtree, node, right subtree
PostorderVisit children before node
Level-orderVisit vertices by depth

These traversals are especially important for rooted and binary trees.

For example, expression trees use postorder traversal for evaluation and inorder traversal for symbolic display.

10.18 Example

Let

V={a,b,c,d,e,f} V=\{a,b,c,d,e,f\}

and

E={{a,b},{a,c},{b,d},{b,e},{c,f}}. E= \{\{a,b\},\{a,c\},\{b,d\},\{b,e\},\{c,f\}\}.

The graph is connected.

The graph has

6 6

vertices and

5 5

edges.

Since

5=61, 5 = 6-1,

it satisfies the tree edge formula.

No cycle exists, so the graph is a tree.

The leaves are

d,e,f. d,e,f.

The unique path from dd to ff is

d,b,a,c,f. d,b,a,c,f.

Removing the edge

{a,c} \{a,c\}

disconnects the graph. Adding the edge

{d,f} \{d,f\}

creates exactly one cycle.

10.19 Summary

A tree is a connected acyclic graph. Trees have exactly

n1 n-1

edges, contain unique paths between vertices, and become disconnected when any edge is removed.

Forests are acyclic graphs whose components are trees. Rooted trees introduce hierarchy through parent-child relations. Binary trees restrict each vertex to at most two children.

Trees are minimal connected graphs and maximal acyclic graphs. They appear throughout graph theory, combinatorics, algorithms, optimization, and computer science because they provide the simplest possible connected structures.