Discrete Mathematics and Combinatorics

Trees in Graph Theory and Their Key Properties

Learn what makes a graph a tree, why it has one edge fewer than vertices, and how trees are counted and used.

Key takeaways

  • A finite tree on n vertices has exactly n − 1 edges and exactly one path between each pair of vertices.
  • Every tree with at least two vertices has at least two leaves, which makes proofs by induction natural.
  • Several different pairs of properties each characterize trees, so you can check whichever is easiest.
  • Cayley's formula says there are n^(n−2) different trees on n labeled vertices.
  • Rooted binary trees limit how quickly any method based on yes-or-no questions can work.

A tree is a graph that is connected and has no cycles. A graph is a collection of vertices (points) joined by edges (links). "Connected" means you can get from any vertex to any other, and a cycle is a closed route that returns to its start without repeating a vertex or edge.

Trees are the leanest way to hold a network together. A tree with n vertices has exactly n − 1 edges, there is exactly one path between any two vertices, and removing any edge breaks it apart. Family trees of descendants, folder hierarchies and knockout tournaments all have this shape.

Many ways to say the same thing

For a finite graph G with n ≥ 1 vertices, the following statements are equivalent. Any one of them can serve as the definition.

Description Meaning
Connected and acyclic The standard definition
Connected with n − 1 edges As few edges as connection allows
Acyclic with n − 1 edges As many edges as avoiding cycles allows
One path between each pair No choices of route
Connected, but not after removing any edge Minimally connected
Acyclic, but not after adding any new edge Maximally acyclic

To see why the path property holds, suppose two vertices were joined by two different paths. Where the paths split and later rejoin, they form a cycle, which a tree cannot have. So there is at most one path, and connectedness gives at least one.

Adding a new edge between two vertices of a tree therefore creates exactly one cycle: the new edge plus the old path between its ends.

Leaves and the edge count

A leaf is a vertex of degree 1, where degree means the number of edges at a vertex. Every finite tree with at least two vertices has at least two leaves. Take a longest path in the tree. An end of that path cannot have a second neighbor off the path, or the path could be extended. It cannot have a second neighbor on the path, or there would be a cycle. So both ends are leaves.

Now the edge count follows by mathematical induction:

Claim: a tree with n vertices has n − 1 edges.
Base:  n = 1 has 0 edges.
Step:  take a tree with n ≥ 2 vertices and delete a leaf and its edge.
       What remains is still connected and acyclic, with n − 1 vertices.
       By hypothesis it has n − 2 edges, so the original had n − 1.

A graph with no cycles that may be disconnected is called a forest. If it has n vertices and k separate trees, it has n − k edges, since each tree contributes one fewer edge than vertices.

Counting leaves from degrees

By the handshaking lemma, the degrees of a tree add to 2(n − 1). Rearranging gives a neat formula for trees with at least two vertices:

number of leaves = 2 + sum of (deg(v) − 2) over vertices with deg(v) ≥ 3

A tree with one vertex of degree 5, one of degree 3 and no other branching therefore has 2 + 3 + 1 = 6 leaves, no matter how long its paths are.

In chemistry, the carbon skeletons of alkanes are trees. Arthur Cayley's interest in counting such isomers was an early application of the subject.

Spanning trees

A spanning tree of a connected graph is a tree that uses all its vertices and some of its edges. Every finite connected graph has one: while a cycle remains, delete one of its edges. The graph stays connected, and the process must end.

Spanning trees are the skeletons of networks. If each edge has a cost, you can ask for the cheapest skeleton, the minimum spanning tree. Exploring a graph breadth first (nearest vertices first) or depth first (as far as possible before backing up) also produces spanning trees.

Counting labeled trees

How many different trees can you build on n named vertices? Cayley's formula says n^(n−2). For n = 3 there are 3, one for each choice of middle vertex. For n = 4 there are 16, made up of 12 paths and 4 stars.

A beautiful proof uses the Prüfer sequence. Number the vertices 1 to n. Repeatedly delete the leaf with the smallest number and write down its neighbor, stopping when two vertices remain.

Take the tree with edges 1–4, 2–4, 3–4, 4–5 and 5–6:

remove leaf 1, record 4
remove leaf 2, record 4
remove leaf 3, record 4
remove leaf 4, record 5        (4 has become a leaf)
two vertices remain: 5 and 6
sequence: 4, 4, 4, 5

Each number appears one time fewer than its degree: vertex 4 has degree 4 and appears three times. The process can be reversed, so trees on n labeled vertices match exactly with sequences of length n − 2 drawn from n symbols. There are n^(n−2) of those. This is a model combinatorial proof.

Encoding a labeled tree as a Prüfer sequence
1 Find a leaf Choose the leaf with the smallest label 2 Record Write down the label of its neighbor 3 Delete Remove the leaf and its edge 4 Repeat Stop when two vertices remain Find a leaf Choose the leaf with the smallest label 1 Record Write down the label of its neighbor 2 Delete Remove the leaf and its edge 3 Repeat Stop when two vertices remain 4

Rooted trees and binary trees

Choose one vertex as the root and the tree gains a direction. Each other vertex has a unique parent, the next vertex on the path back to the root. Its depth is the length of that path, and the height of the tree is the greatest depth.

In a binary tree, each vertex has at most two children. With height h, it has at most 2^h leaves and at most 2^(h+1) − 1 vertices in total. In a full binary tree, where every vertex has 0 or 2 children, the number of leaves is one more than the number of internal vertices.

A knockout tournament is a full binary tree. With 64 players as leaves there are 63 internal vertices, so 63 matches. You can also see this directly: each match eliminates exactly one player.

Decoding a sequence back into a tree

Going backward shows why nothing is lost in the encoding. Start with the sequence 4, 4, 4, 5 and the labels 1 to 6. At each step, pick the smallest label that is still available and does not appear in the rest of the sequence. Join it to the first number in the sequence, then cross both off.

sequence 4 4 4 5   available 1 2 3 4 5 6   join 1–4
sequence   4 4 5   available   2 3 4 5 6   join 2–4
sequence     4 5   available     3 4 5 6   join 3–4
sequence       5   available       4 5 6   join 4–5
sequence   empty   available         5 6   join 5–6

These are exactly the original five edges. Every sequence of the right length decodes to a tree in this way, and different sequences give different trees.

The correspondence answers other counting questions too. A vertex of degree d appears d − 1 times, so the leaves are the labels that never appear. To count trees on 6 labeled vertices in which vertex 1 is a leaf, count sequences of length 4 that avoid the symbol 1. There are 5⁴ = 625 of them, out of 6⁴ = 1,296 trees in all.

Finding the middle of a tree

Trees have a natural center. Delete all the leaves at once, then delete all the leaves of what remains, and continue. You end with either a single vertex or a single edge. This is the center of the tree.

On a path with five vertices, one round leaves the middle three and a second round leaves the middle one. On a path with six vertices, you finish with the middle edge. The center minimizes the greatest distance to any other vertex, which makes it a sensible place for a depot or a server in a tree-shaped network.

The center also helps you decide whether two trees have the same shape. Root each at its center and compare the branches level by level.

Why trees limit algorithms

Any sorting method that works only by comparing pairs of items can be drawn as a binary tree. Each internal vertex is a comparison and each leaf is a final ordering. To handle n distinct items, the tree needs at least n! leaves.

Since a binary tree of height h has at most 2^h leaves, you need h ≥ log₂ n!. For 5 items, n! = 120 and 2^6 = 64 is too small, so some input requires at least 7 comparisons. In general log₂ n! grows like n log₂ n, which explains why comparison sorting cannot beat that rate in the worst case. The notation is covered in Big O notation.

The same counting idea applies to balance puzzles. A weighing with three outcomes is a vertex with three children.

Where trees appear and common slips

Trees organize search structures in databases, parse the structure of arithmetic expressions, model evolutionary relationships and underlie efficient data compression codes. In each case, the uniqueness of paths gives an unambiguous address for every item.

Keep these points straight:

  • A tree need not look like a plant. A single straight path is a tree, and so is a star.
  • The formula n − 1 alone is not enough. A triangle plus an isolated point has 4 vertices and 3 edges but is not a tree.
  • Cayley's formula counts labeled trees. The number of distinct shapes is much smaller; on 4 vertices there are only 2, the path and the star.
  • Infinite trees behave differently. A path stretching forever in one direction has only one leaf.

If you want to keep exploring, trees are the usual starting point for strong induction arguments, because cutting one edge leaves two smaller trees of unpredictable sizes.

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 45 articles in Discrete Mathematics and Combinatorics →

Latest news on this topic