The delta of the river Lena in Siberia seen from the Landsat 7 satellite in 2000, its channels branching across the tundra like the limbs of a tree
Unit 04 · All masterclasses · 80 min

Trees and Spanning Trees

Characterizations of trees, Cayley's formula, and the greedy algorithms of Kruskal and Prim
Image: NASA and USGS, Landsat 7, 2000, public domain

Trees defined and characterized five ways, with the proofs by induction through a leaf. Cayley's formula counts the labelled trees on n vertices through Prüfer codes, Kirchhoff's matrix-tree theorem counts the spanning trees of any graph, and the much smaller count of unlabelled trees is drawn. Minimum spanning trees follow: the cut property, Kruskal's and Prim's algorithms with their correctness proofs, and the electrical networks of Moravia where Borůvka found the problem in 1926.

Preview: the beginning of the unit

A road network, a family tree, the folders on a computer, and the carbon skeleton of a molecule share one shape: they are connected and they contain no cycle. Graphs of this kind are called trees, and they are the simplest connected graphs there are, in a sense that this unit makes exact. The surprise is how much can be said about them. Every tree on \(n\) vertices has exactly \(n - 1\) edges, there are exactly \(n^{n-2}\) trees on \(n\) labelled vertices, and the cheapest way to connect \(n\) towns by cables is found by an algorithm so simple that it fits in two sentences and was first found in 1926, in Czech and without the word graph, by a mathematician who had been asked to help electrify a region.

1 Trees and forests

A graph is acyclic when it contains no cycle, and an acyclic graph is also called a forest. A tree is a connected forest, that is, a connected graph without a cycle. Each component of a forest is a tree, which is where the name comes from. A vertex of degree 1 in a tree or forest is called a leaf. Figure 1 shows a tree \(T\) on 8 vertices that this unit uses again and again, a forest, and a connected graph that is not a tree because it contains a cycle.

(a) The tree \(T\) with the edges \(14, 24, 35, 46, 56, 67\), and \(78\); its four leaves are shaded. (b) A forest of three trees on 10 vertices with…
Figure 1. (a) The tree \(T\) with the edges \(14, 24, 35, 46, 56, 67\), and \(78\); its four leaves are shaded. (b) A forest of three trees on 10 vertices with \(10 - 3 = 7\) edges. (c) A connected graph on 8 vertices with 8 edges and one cycle, so not a tree; the four thick edges are bridges, edges whose removal would disconnect the graph, a term that Section 1.1 takes up.

Trees have leaves, and the leaves are what make proofs about trees work. The first claim is that every tree with at least two vertices has at least two leaves, and the argument that proves it is the longest path argument of Unit 1. Let \(T\) be a tree with at least two vertices and let \(P = x_1 x_2 \ldots x_\ell\) be a path in \(T\) with as many vertices as any path in \(T\) has. Every neighbour of \(x_1\) lies on \(P\), since a neighbour off the path would extend it. But \(x_1\) has no neighbour \(x_j\) with \(j \ge 3\) either, because the edge \(x_1 x_j\) together with the piece \(x_1 x_2 \ldots x_j\) of \(P\) would form a cycle, and a tree has none. So the only neighbour of \(x_1\) is \(x_2\), and \(x_1\) is a leaf; the same holds for \(x_\ell\) at the other end, and since \(T\) has at least two vertices, \(\ell \ge 2\) and the two ends are different vertices.

The second sentence of the box deserves its one line of proof. Deleting a vertex never creates a cycle, and if \(T - v\) were disconnected, some path of \(T\) between two vertices of \(T - v\) would pass through \(v\); but a path passes through an inner vertex by two different edges, and \(v\) has only one. So \(T - v\) is a tree. This is the move that every induction on trees makes: remove a leaf, apply the statement to the smaller tree, and put the leaf back.

1.1 Five ways to say “tree”

The definition of a tree asks for two things, connectedness and the absence of cycles. The theorem below says that either one, together with the right number of edges, forces the other, and that two further properties describe trees just as well. An edge \(e\) of a connected graph \(G\) is a bridge when \(G - e\) is disconnected; in Figure 1(c) the four thick edges are bridges and the edges of the cycle are not, since the rest of the cycle keeps the ends of a cycle edge joined.

The full unit is part of the program

Want to see a complete unit first? Unit 3, Euler Tours and Hamilton Cycles, is free to read.