A tree is a connected graph with no cycles.
This definition is short, but it describes one of the most important graph classes. Trees appear in pure graph theory, algorithms, data structures, networks, logic, chemistry, parsing, file systems, and hierarchical models. They are useful because they combine two strong properties: every vertex is reachable from every other vertex, and there is no circular redundancy.
Equivalently, a tree is an undirected graph in which every two distinct vertices are joined by exactly one simple path. This unique-path property is one of the main reasons trees are easy to reason about. General graph paths may branch, repeat, and form cycles. In a tree, there is only one route between two vertices.
26.1 Definition
Let
be an undirected graph, where is the set of vertices and is the set of edges.
The graph is called a tree if it satisfies both conditions:
- is connected.
- contains no cycle.
A graph with no cycles is called acyclic. Thus a tree is a connected acyclic graph.
A graph that is acyclic but not necessarily connected is called a forest. Each connected component of a forest is a tree.
26.2 Examples
The following graph is a tree:
It is connected, since every vertex can be reached from every other vertex. It has no cycle, since no path returns to its starting vertex without repeating an edge or vertex.
The following graph is not a tree:
It is connected, but it contains a cycle:
The following graph is also not a tree:
It has no cycle, but it is disconnected. It is a forest with two components.
26.3 Basic Terminology
A vertex of degree in a tree is called a leaf. A vertex of degree greater than is often called an internal vertex, especially when the tree is viewed as a hierarchical structure.
A path graph is a tree in which the vertices can be arranged in a single line.
A star graph is a tree with one central vertex adjacent to every other vertex. If it has vertices, then the central vertex has degree , and all other vertices are leaves.
A subtree is a subgraph that is itself a tree.
26.4 The Unique Path Property
One of the fundamental characterizations of a tree is the following theorem.
Theorem 26.1
Let be an undirected graph. Then is a tree if and only if every two distinct vertices of are joined by exactly one simple path.
Proof
Suppose first that is a tree. Since is connected, every two vertices are joined by at least one path.
It remains to show that there cannot be two different simple paths between the same two vertices. Suppose there were two different simple paths from to . Follow the first path from until it first differs from the second path. Since both paths eventually reach , the two paths must later meet again. The two different portions between the first separation point and the first meeting point form a cycle. This contradicts the assumption that is acyclic.
Therefore the path between any two vertices is unique.
Conversely, suppose every two distinct vertices of are joined by exactly one simple path. Then is connected by definition. If contained a cycle, then any two vertices on that cycle would be joined by two different simple paths along the two directions around the cycle. This contradicts uniqueness.
Hence is connected and acyclic. Therefore is a tree.
26.5 Edges in a Finite Tree
A finite tree has one fewer edge than vertex.
Theorem 26.2
If is a tree with vertices, then
Proof
We prove the result by induction on .
For , the tree has one vertex and no edges. Thus
Assume the statement holds for every tree with vertices. Let be a tree with vertices, where .
Every finite tree with at least two vertices has a leaf. Let be a leaf, and let be the unique edge incident with . Remove and . The remaining graph is still connected and acyclic, so it is a tree with vertices.
By the induction hypothesis, the remaining tree has
edges. Adding back the removed edge gives
edges.
Thus every tree with vertices has edges.
26.6 Leaves
Leaves are unavoidable in finite trees.
Theorem 26.3
Every finite tree with at least two vertices has at least two leaves.
Proof
Let be a finite tree with at least two vertices. Choose a longest simple path in :
The endpoint must have degree . If it had another neighbor not equal to , then the path could be extended, unless that neighbor already appeared on the path. If the neighbor already appeared on the path, a cycle would occur. Both cases are impossible.
Thus is a leaf. The same argument applies to . Therefore has at least two leaves.
This theorem is often used in induction proofs about trees. One removes a leaf, proves a statement about the smaller tree, and then adds the leaf back.
26.7 Minimal Connectivity
Trees are minimally connected graphs.
This means a tree is connected, but removing any edge disconnects it.
Theorem 26.4
If is a tree and is an edge of , then is disconnected.
Proof
Let
Since is a tree, there is a unique path from to . That path is the single edge . If is removed, there is no remaining path from to . Hence the graph becomes disconnected.
This property says that every edge of a tree is essential for connectivity.
26.8 Maximal Acyclicity
Trees are also maximally acyclic.
This means a tree has no cycle, but adding any new edge creates a cycle.
Theorem 26.5
Let be a tree. If and are nonadjacent vertices of , then adding the edge creates exactly one cycle.
Proof
Since is connected, there is a unique simple path from to . Add the new edge . The old path from to , together with the new edge, forms a cycle.
There cannot be another cycle using the new edge, since that would require another distinct path from to in . There cannot be a cycle avoiding the new edge, since itself has no cycles.
Therefore exactly one cycle is created.
26.9 Equivalent Characterizations
For a finite undirected graph with vertices, the following conditions are equivalent:
| Condition | Meaning |
|---|---|
| is connected and acyclic | Definition of a tree |
| Every two vertices are joined by a unique simple path | Unique route property |
| is connected and has edges | Minimal connected graph |
| is acyclic and has edges | Maximal acyclic graph |
| Removing any edge disconnects | Every edge is a bridge |
| Adding any missing edge creates a cycle | No more edges can be added safely |
These equivalent forms let us recognize trees from different kinds of information. Sometimes connectivity and absence of cycles are easiest to check. Sometimes the edge count is easiest. Sometimes the unique-path property is the most useful.
26.10 Rooted and Unrooted Trees
A tree is unrooted when no vertex has been singled out as special.
A rooted tree is a tree with one distinguished vertex called the root. Once a root is chosen, the tree obtains a hierarchical structure.
If is the root and is another vertex, the unique path from to defines the position of in the hierarchy.
In a rooted tree:
| Term | Meaning |
|---|---|
| Root | Distinguished starting vertex |
| Parent | Previous vertex on the path to the root |
| Child | Adjacent vertex farther from the root |
| Ancestor | Vertex lying on the path from the root |
| Descendant | Vertex below another vertex in the rooted structure |
| Leaf | Vertex with no children |
| Depth | Distance from the root |
| Height | Maximum depth of a vertex |
Rooted trees are central in computer science. They model syntax trees, decision trees, search trees, directory trees, and hierarchical indexes.
26.11 Trees and Recursion
Trees naturally support recursive definitions.
A rooted tree consists of a root together with zero or more subtrees attached to the root. Each child of the root is the root of a smaller rooted tree.
This recursive structure explains why many tree algorithms are recursive. To process a tree, one processes the root and then processes each subtree.
For example, the size of a rooted tree can be defined recursively:
where are the subtrees rooted at the children of the root.
The height can also be defined recursively:
26.12 Spanning Trees
Let be a connected graph. A spanning tree of is a subgraph such that:
- contains every vertex of .
- is a tree.
- Every edge of is an edge of .
A spanning tree keeps all vertices but removes enough edges to destroy all cycles.
Every finite connected graph has a spanning tree. One way to obtain one is to repeatedly remove an edge from a cycle. Removing such an edge does not disconnect the graph. Since the graph is finite, this process eventually stops. The final graph is connected and acyclic, so it is a spanning tree.
Spanning trees are important because they give cycle-free skeletons of connected graphs. They appear in network design, routing, clustering, and optimization.
26.13 Trees in Algorithms
Trees are among the most important structures in graph algorithms.
Breadth-first search builds a BFS tree. This tree records shortest-path distances from a starting vertex in an unweighted graph.
Depth-first search builds a DFS tree. This tree records the recursive structure of graph exploration.
Minimum spanning tree algorithms, such as Kruskal’s algorithm and Prim’s algorithm, find a spanning tree of minimum total edge weight in a connected weighted graph.
Many graph problems become easier on trees. Since trees have no cycles, dynamic programming can often solve problems on trees more efficiently than on general graphs.
Examples include:
| Problem | Tree advantage |
|---|---|
| Connectivity | Unique path between vertices |
| Shortest path | Only one simple path exists |
| Dynamic programming | Subproblems separate at vertices |
| Matching | Can be solved recursively |
| Independent set | Can be solved by parent-child cases |
| Network design | Minimal connected backbone |
26.14 Trees as Minimal Networks
A tree is the smallest connected structure on a given set of vertices.
If a connected graph has vertices, it must have at least edges. A tree reaches this lower bound exactly.
This makes trees natural models for minimal networks. A communication network that connects all sites with no redundant link has the structure of a tree. If any link fails, the network disconnects. Adding one extra link creates a cycle and introduces redundancy.
Thus trees represent the boundary between disconnected and cyclic structure.
They are connected enough to hold the graph together, but sparse enough to contain no alternate route.
26.15 Summary
A tree is a connected acyclic graph. This simple definition leads to several equivalent descriptions.
A finite graph is a tree precisely when it has unique simple paths between vertices, or when it is connected with edges, or when it is acyclic with edges.
Trees are minimally connected and maximally acyclic. Removing any edge disconnects them. Adding any missing edge creates a cycle.
Their importance comes from this balance. They are simple enough to support induction, recursion, and efficient algorithms, yet rich enough to model hierarchy, dependency, search, and minimal connectivity.