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:
- Every pair of vertices is connected.
- 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 is a tree when:
- is connected.
- contains no cycle.
For example, the graph with vertex set
and edge set
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
is a forest with two components:
and
Each component is a tree.
10.3 Basic Examples
Several standard graph families are trees.
| Graph | Tree? | Reason |
|---|---|---|
| Path graph | Yes | Connected and acyclic |
| Cycle graph | No | Contains a cycle |
| Complete graph , | No | Contains cycles |
| Star graph | Yes | Connected and acyclic |
| Empty graph on one vertex | Yes | Connected and acyclic |
The simplest nontrivial tree is
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 is a tree if and only if every pair of distinct vertices is joined by exactly one path.
Proof
Suppose is a tree.
Because is connected, at least one path joins every pair of vertices.
Suppose two distinct paths joined vertices and . Traversing one path from to 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 has vertices, then it has exactly
edges.
Proof
The proof proceeds by induction on .
If
then the tree consists of one vertex and no edges, so the formula holds.
Assume every tree with vertices has edges.
Let be a tree with vertices. Since is finite and acyclic, it contains a leaf. Remove a leaf and its incident edge.
The remaining graph is still a tree. It has
vertices, so by induction it has
edges.
Restoring the removed edge gives
edges in total.
Thus every tree with vertices has exactly
edges.
This formula is one of the defining numerical properties of trees.
10.6 Leaves
A leaf is a vertex of degree .
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
be a longest path in the tree.
Suppose had degree greater than . Then some edge from would lead to a vertex not already on the path. Extending the path through that edge would produce a longer path, contradicting maximality.
Therefore
Similarly,
Thus both endpoints are leaves.
This theorem shows that trees always branch outward toward degree- vertices.
10.7 Equivalent Characterizations of Trees
Several different properties characterize trees.
Theorem
For a finite graph with vertices, the following are equivalent:
- is a tree.
- is connected and has edges.
- is acyclic and has edges.
- Every pair of vertices is joined by exactly one path.
- is connected, and removing any edge disconnects it.
- 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
be an edge of a tree .
Since has exactly one path between any two vertices, the edge lies on the unique path between and .
Removing destroys that path. Therefore and 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 and be nonadjacent vertices of a tree .
Because is connected, a unique path joins and .
Adding the edge
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 is the root, then every vertex except has a unique parent: the previous vertex on the unique path from .
Vertices connected downward from a vertex are called its children.
For example:
r
/ | \
a b c
|
dHere:
- is the root.
- are children of .
- is a child of .
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 is the preceding vertex on the path from the root.
- A child of is a vertex whose parent is .
- Vertices with the same parent are siblings.
These relations convert the tree into a hierarchical structure.
If
is above
on the root path, then is an ancestor of , and is a descendant of .
10.12 Levels and Height
The level or depth of a vertex is its distance from the root.
The root has depth .
The height of a rooted tree is the maximum depth of any vertex.
For example:
r
/ \
a b
/ \
c dThe depths are:
| Vertex | Depth |
|---|---|
| 0 | |
| 1 | |
| 1 | |
| 2 | |
| 2 |
The tree height is .
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:
| Structure | Description |
|---|---|
| Binary search tree | Ordered search structure |
| Heap | Priority queue structure |
| Expression tree | Arithmetic expression representation |
| Huffman tree | Prefix coding structure |
A full binary tree is a binary tree in which every internal vertex has exactly two children.
10.14 Spanning Trees
Let
be a connected graph.
A spanning tree of is a subgraph of that:
- Contains every vertex of .
- Is a tree.
A spanning tree preserves connectivity while removing cycles.
For example, if is a cycle graph
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 vertices is
This result is called Cayley’s formula.
For example:
| Number of labeled trees | |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 3 |
| 4 | 16 |
| 5 | 125 |
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:
| Traversal | Strategy |
|---|---|
| Preorder | Visit node before children |
| Inorder | Visit left subtree, node, right subtree |
| Postorder | Visit children before node |
| Level-order | Visit 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
and
The graph is connected.
The graph has
vertices and
edges.
Since
it satisfies the tree edge formula.
No cycle exists, so the graph is a tree.
The leaves are
The unique path from to is
Removing the edge
disconnects the graph. Adding the edge
creates exactly one cycle.
10.19 Summary
A tree is a connected acyclic graph. Trees have exactly
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.