Trees
A network hangs together and has no loop. How many links must it have, and what else does that one count force?
Where you are 10 in Introductory graph theory
Why this exists
Some networks hang together with nothing to spare: the branching of a river, the folders on a computer, the chain of atoms in a fuel molecule. There is one route between any two points and no loop. These are trees. Cut one link and a tree falls apart; add one and it gains a loop. And one count holds for every tree: n points need exactly n - 1 links, the fewest any connected network can have. That count lets leaves, degrees and chemical formulas be read off without a drawing.
Definition
This lesson takes two days. Day 1 is trees, forests, leaves, the edge count and unique paths (Results 1 to 7, Examples 1 to 3). Day 2 is the fewest edges of a connected graph, degrees, rooted trees and labeled trees (Results 8 to 11, Examples 4 to 7).
Notation is that of Degree, the handshake lemma and complete graphs and Walks, paths, cycles and connected graphs: G = (V, E) is a finite simple graph, with degrees \deg(v), paths, cycles, components and distance d(u, v) as there.
- A tree is a connected graph with no cycle. A single vertex is a tree with no edges.
- A forest is a graph with no cycle. Its components are trees.
- A leaf is a vertex of degree 1, and n_i is the number of vertices of degree i.
- G - e removes the edge e and keeps every vertex. G - v removes the vertex v and every edge at v. For non-adjacent vertices u \ne v, G + uv adds the edge uv.
- (Day 2) A rooted tree is a tree with one vertex r chosen as root. The level of v is d(r, v) and the height is the largest level. For v \ne r, the parent of v is the vertex just before v on the path from r to v (unique by Result 5), and v is its child.
- (Day 2) A labeled tree on \{1, \ldots, n\} is a tree with that vertex set. Two are the same exactly when they have the same edges.
Intuition
Ondina studies pocket gophers. Figure 1 is her map of one den: chambers are vertices, dug runs are edges. From d to j a gopher has no choice of route; the dead ends d, g, h, i, j are the leaves. Fill in one run and the den splits in two. Dig one new run and the den gains a loop, and only one.
Why n - 1 runs? Fill in a dead end together with its run. What is left is still a tree, with one chamber and one run fewer. Repeat until one chamber and no runs remain. Chambers and runs fell together every time, so there was one more chamber than runs at the start.
Results
1. Leaves. Every tree with at least two vertices has at least two leaves: both ends of any longest path are leaves.
2. Removing a leaf. If \ell is a leaf of a tree T, then T - \ell is a tree.
3. The edge count. A tree with n vertices has exactly n - 1 edges.
4. Forests. A forest with n vertices and c components has exactly n - c edges.
5. Unique paths. A graph is a tree exactly when every two of its vertices are joined by exactly one path.
6. Removing and adding an edge. Let T be a tree. For every edge xy, T - xy has exactly two components, one containing x and one y, both trees. For non-adjacent u, v, T + uv has exactly one cycle: uv together with the path from u to v in T.
7. Two of three. Let G have n vertices. Any two of (a) G is connected, (b) G has no cycle, (c) G has n - 1 edges, imply the third, so any two make G a tree.
8. Fewest edges (Day 2). A connected graph with n vertices has at least n - 1 edges, with equality only for a tree. A graph with n vertices and c components has at least n - c edges, with equality only for a forest.
9. Degrees in a tree (Day 2). In a tree with n vertices the degrees add to 2n - 2, and if n \ge 2,
So a tree whose degrees are all 1 or 3 has n_1 = n_3 + 2.
10. Levels (Day 2). In a rooted tree each vertex except the root has exactly one parent, and the ends of every edge are a parent and its child, on levels that differ by exactly 1.
11. Cayley’s formula (Day 2). For n \ge 2 there are exactly n^{n-2} labeled trees on \{1, \ldots, n\}. This lesson states it without proof.
Why it is true
Result 1. Proof. A tree with two or more vertices has an edge, and a path repeats no vertex, so there are finitely many paths and a longest one, (v_0, \ldots, v_k), has k \ge 1. A neighbor w \ne v_{k-1} of v_k would either be some v_i with i \le k - 2, closing the cycle (v_i, \ldots, v_k, v_i), or lie off the path and extend it. Both are impossible, so \deg(v_k) = 1, and likewise \deg(v_0) = 1. \square
Result 2. Proof. T - \ell has no cycle, since T has none. A vertex strictly inside a path has two neighbors on it, so a path in T between two vertices other than \ell avoids \ell and lies in T - \ell. \square
Result 3. Proof. By induction on n. A one-vertex tree has 0 edges. Suppose every tree with k \ge 1 vertices has k - 1 edges, and let T have k + 1. By Result 1 it has a leaf \ell; by Result 2, T - \ell is a tree with k vertices and so k - 1 edges; T has one edge more, k in all. \square The step shrinks an arbitrary tree. Growing a tree by adding a leaf would prove the count only for the trees built that way.
Result 4. Proof. The components are trees with n_1 + \cdots + n_c = n vertices, and every edge lies in one (Walks, paths, cycles and connected graphs, Result 2), so there are (n_1 - 1) + \cdots + (n_c - 1) = n - c edges. \square
Result 5. Proof. In a tree T two vertices are joined by a walk, and a walk contains a path with the same ends (Walks, paths, cycles and connected graphs, Result 1). Suppose two different paths P, Q from u to v exist, chosen with the least total length. Then u \ne v, since (u) is the only path from u to u. If they shared a vertex w \ne u, v, splitting both at w would give a pair of different paths with smaller total length. So they meet only at u and v, their lengths add to at least 3, and P followed by Q backward is a cycle: impossible.
Conversely, if every two vertices are joined by exactly one path, G is connected, and a cycle (v_0, v_1, \ldots, v_{k-1}, v_0) would give two paths (v_0, v_1) and (v_0, v_{k-1}, \ldots, v_1). \square
Result 6. Proof. By Result 5 the only path from x to y is (x, y), so T - xy does not join them. For any w, the path from w to x either avoids xy or ends with the step from y to x, so w is joined to x or to y in T - xy: exactly two components, each with no cycle.
A cycle of T + uv uses uv, and the rest of it is a path from v to u in T, of which there is exactly one, of length at least 2. \square
Result 7. Proof. First a fact: if e = xy lies on a cycle (x, y, w_1, \ldots, w_m, x) of a connected graph, then removing e keeps it connected, since any walk can replace a step along e by (y, w_1, \ldots, w_m, x) or its reverse.
(a) and (b) give (c) by Result 3. (b) and (c): by Result 4, n - c = n - 1, so c = 1. (a) and (c): if G had a cycle, remove edges on cycles one at a time until none is left. The graph stays connected, so it ends as a tree on n vertices with fewer than n - 1 edges, against Result 3. \square
Result 8. Proof. The removal process of Result 7 turns a connected G into a tree on its n vertices, keeping n - 1 of its edges and removing one exactly when G has a cycle. For c components, add the bounds for each. \square
Result 9. Proof. By the handshake lemma (Degree, the handshake lemma and complete graphs, Result 1) and Result 3 the degrees add to 2n - 2. For n \ge 2 no vertex is isolated, so \sum_i n_i = n and \sum_i i\, n_i = 2n - 2. Subtracting twice the first gives \sum_i (i - 2)\, n_i = -2, where the i = 1 term is -n_1 and the i = 2 term is 0. \square
Result 10. Proof. The path from r to v \ne r is unique, so v has one parent. For an edge xy, let P be the path from r to x. If y is off P, then P followed by y is the path to y, and x is the parent of y. If y is on P, the part of P from y to x and the path (y, x) coincide by Result 5, so y is the parent of x. \square
Result 11. Stated without proof; Keller and Trotter, Section 5.6, give one. Example 7 and Exercises 19 and 20 check small cases.
Worked examples
Day 1: tree, forest or neither
Each graph has vertex set \{p, q, r, s, t, u\}. Is it a tree, a forest that is not a tree, or neither? (a) Edges pq, qr, rs, st, tu, uq. (b) Edges pq, pr, ps, tu. (c) Edges pr, qr, rs, st, tu.
Solution(a) (q, r, s, t, u, q) is a cycle of length 5, so neither. It is connected with 6 edges, not 5, and by Result 7 that alone forces a cycle.
(b) A vertex on a cycle has two neighbors on it, and only p has degree above 1, so there is no cycle: a forest, with components \{p, q, r, s\} and \{t, u\}, and 4 = 6 - 2 edges (Result 4).
(c) Every vertex reaches r, so the graph is connected, and it has 5 = 6 - 1 edges. By Result 7 it is a tree, with no search for cycles. The ends p, u of the longest path (p, r, s, t, u) are leaves, as Result 1 says, and q is a third.
Day 1: routes in the den
In Figure 1, find the path from d to j, every cycle after a new run hi is dug, and the pieces left if instead the run ac is filled in.
SolutionFrom d the only way out is to b, and from j to f; climbing toward a gives (d, b, a, c, f, j), the only path by Result 5, so d(d, j) = 5.
The path from i to h is (i, f, c, a, b, e, h), so by Result 6 the run hi closes exactly one cycle, (h, i, f, c, a, b, e, h), of length 7.
Filling in ac leaves two components (Result 6), \{a, b, d, e, g, h\} and \{c, f, i, j\}, with 5 + 3 = 8 = 10 - 2 edges, as Result 4 requires.
Day 1: reading structure from counts
Ondina maps a second den with 31 chambers and 30 runs. (a) If every chamber can be reached from every other, show there is no loop. (b) If instead there is a loop, show some two chambers are not joined. (c) A third map has 31 chambers, 24 runs and no loop. How many pieces does it have?
Solution(a) Connected with 30 = 31 - 1 edges, so no cycle by Result 7.
(b) If it were connected, (a) would rule out the cycle.
(c) A forest, so 31 - c = 24 by Result 4, and c = 7.
Day 2: cutting a connected graph down to a tree
The graph H has vertices 1 to 7 and edges 12, 13, 23, 34, 45, 46, 56, 47. Remove edges on cycles until no cycle is left. How many go, in any order?
SolutionH is connected, with 8 edges, more than 7 - 1, so it is not a tree (Result 8). The edge 13 lies on (1, 2, 3, 1); after removing it, (4, 5, 6, 4) remains, so remove 46. The edges left, 12, 23, 34, 45, 56, 47, form a connected graph with 6 edges, a tree by Result 7.
Every order ends at a tree on 7 vertices, which has 6 edges (Result 3), so exactly 8 - 6 = 2 edges go every time. That final tree reaches every vertex; choosing the cheapest such tree is Spanning trees and minimum spanning trees.
Day 2: leaves from the other degrees
A tree has 3 vertices of degree 4, 5 of degree 3, 2 of degree 2, and every other vertex is a leaf. How many leaves, vertices and edges does it have?
SolutionBy Result 9, n_1 = 2 + (4 - 2) \cdot 3 + (3 - 2) \cdot 5 = 2 + 6 + 5 = 13; degree 2 adds nothing. So n = 3 + 5 + 2 + 13 = 23, with 22 edges. Check: 4 \cdot 3 + 3 \cdot 5 + 2 \cdot 2 + 13 = 44 = 2 \cdot 22. Exercise 22 shows such a tree exists.
Day 2: alkanes are trees
An alkane \mathrm{C}_n\mathrm{H}_{2n+2} has n \ge 1 carbon atoms and 2n + 2 hydrogen atoms joined by single bonds, 4 at each carbon and 1 at each hydrogen. With atoms as vertices and bonds as edges, show the molecule is a tree, that its carbons alone form a tree, and find both carbon skeletons for \mathrm{C_4H_{10}}.
SolutionThere are 3n + 2 atoms and, by the handshake lemma, \displaystyle \frac{4n + (2n + 2)}{2} = 3n + 1 bonds. A molecule hangs together, so the graph is connected with one edge fewer than vertices: a tree by Result 7.
Each hydrogen is a leaf bonded to a carbon. Removing hydrogens one at a time keeps a tree (Result 2), so the carbons and their bonds form a tree, the carbon skeleton. A carbon with k carbon neighbors carries 4 - k hydrogens, so the skeleton fixes the molecule. For n = 4 the skeleton is a path or a star (Example 7): butane and isobutane, Figure 2. In each the counts 4 - k add to 10.
Day 2: checking Cayley’s formula by listing
List the labeled trees on \{1, 2, 3\} and on \{1, 2, 3, 4\}, and compare with n^{n-2}.
SolutionOn 3 vertices, Result 9 gives n_1 = 2, so the tree is a path, fixed by its middle vertex: edges \{12, 13\}, \{12, 23\} or \{13, 23\}, and 3 = 3^{1}.
On 4 vertices there are 3 edges. A vertex of degree 3 uses all of them: a star. Otherwise the degrees are 1 or 2 with n_1 = 2, so they are 2, 2, 1, 1: a path (Figure 3). A star is fixed by its center, 4 trees; a path is an ordering of the labels read either way, \displaystyle \frac{4!}{2} = 12. In all 4 + 12 = 16 = 4^{2}.
For n = 5, a machine test of all \binom{10}{4} = 210 sets of four edges finds 125 = 5^{3} trees. Each agrees with Result 11.
Boundaries
- Finite graphs. The integers with i joined to i + 1 form a connected graph with no cycle and no leaf.
- Leaves need two vertices. The one-vertex tree has none, so Result 1 and the leaf formula of Result 9 need n \ge 2.
- Two of the three, not one. A triangle plus an isolated vertex has 4 vertices and 3 edges and is not a tree.
- Simple graphs. In a multigraph two edges between one pair form a cycle of length 2. A double bond, as in \mathrm{C_2H_4}, makes a multigraph, and Example 6 does not apply.
- Labels, not shapes. On four vertices there are 16 labeled trees but 2 shapes.
Where this goes next
The tree left by the removal process is a spanning tree; the cheapest is Spanning trees and minimum spanning trees. A tree drawn in the plane has one face, and n - (n - 1) + 1 = 2 is the first case of Planar graphs and Euler's formula. Levels alternate even and odd along every edge, so a tree’s vertices take two colors with every edge between them, the start of Bipartite graphs. Searches such as Finding a shortest path grow a rooted tree as they go.
Exercises
Day 1: trees and forests
- Each graph has vertex set \{1, \ldots, 7\}. Is it a tree, a forest that is not a tree, or neither? Give the components of each forest. (a) Edges 12, 23, 34, 45, 56, 67. (b) Edges 13, 35, 15, 24, 46, 67. (c) Edges 17, 27, 37, 47, 56.
- How many edges does a tree with 57 vertices have? How many components does a forest with 57 vertices and 49 edges have?
- A forest has 12 vertices and 4 components. How many edges does it have, and what is the largest number of leaves it can have?
Day 1: paths, adding and removing
Exercises 4 and 5 use the den of Figure 1.
- Find the path from g to i and d(g, i).
- Find the cycle created by a new run dj, and the components left if instead the run cf is filled in.
- Show that every graph with n vertices and at least n edges has a cycle, whether or not it is connected, and give a graph with 8 vertices, 8 edges and exactly one cycle.
Day 1: reasoning
- Let v be a vertex of degree d \ge 1 in a tree T. Prove that T - v is a forest with exactly d components.
- Prove that a connected graph in which removing any one edge leaves a disconnected graph is a tree.
- Prove that a graph with no cycle, in which adding any edge between two non-adjacent vertices creates a cycle, is a tree.
- Let u, v be vertices of a tree. Prove that every walk from u to v passes through every vertex of the path from u to v.
Day 2: counting edges and components
- A region has 26 towns and 31 roads, each joining two towns, and every town can be reached from every other. What is the largest number of roads that can be closed with every town still reachable, and what kind of network is left?
- A graph has 40 vertices and 31 edges. At least how many components does it have, and when exactly that many?
- A connected molecule of 9 carbon atoms and 18 hydrogen atoms has single bonds only, 4 at each carbon and 1 at each hydrogen. Show that its graph has a cycle.
- For the alkane with 7 carbon atoms, find the numbers of hydrogen atoms, atoms and bonds. If the carbon skeleton is a path, how many carbons carry 3 hydrogens?
Day 2: degrees and leaves
- A tree has 4 vertices of degree 3, 2 of degree 5, and every other vertex is a leaf. How many leaves and vertices does it have?
- A tree has 20 vertices, each of degree 1 or 3. How many of each are there? Why can no such tree have 21 vertices?
- Refute with a counterexample: “a graph with n vertices, n - 1 edges and no isolated vertex is a tree.”
Day 2: rooted and labeled trees
- Root the den of Figure 1 at f. Give every level, the parent of a, the children of b and the height. Then find a root that makes the height as small as possible.
- How many labeled trees are there on \{1, \ldots, 6\}? How many labeled trees on \{1, \ldots, 5\} have 5 as a leaf?
- List the labeled trees on \{1, 2, 3, 4\} in which 1 is a leaf, and check the count against the method of Exercise 19.
Day 2: reasoning
- Prove that a tree with a vertex of degree k \ge 1 has at least k leaves.
- Let n \ge 2 and let d_1, \ldots, d_n be positive integers with sum 2n - 2. Prove that some tree on \{1, \ldots, n\} has \deg(i) = d_i for every i.
- Prove that in a rooted tree two children of the same parent are never adjacent.
Answers
- (a) A tree, the path (1, 2, \ldots, 7). (b) Neither: (1, 3, 5, 1) is a cycle. It has 6 = 7 - 1 edges but components \{1, 3, 5\} and \{2, 4, 6, 7\}, failing two conditions of Result 7. (c) A forest, components \{1, 2, 3, 4, 7\} and \{5, 6\}, with 5 = 7 - 2 edges.
- 56 edges (Result 3); 57 - c = 49 gives 8 components (Result 4).
- 12 - 4 = 8 edges. At most 11 leaves: three single edges and a star of 6 vertices give 11. A tree whose s vertices are all leaves has degree sum s = 2s - 2, so s = 2, and 12 leaves would need six components.
- (g, e, b, a, c, f, i), so d(g, i) = 6.
- The cycle (d, j, f, c, a, b, d). Filling in cf leaves \{a, b, c, d, e, g, h\} and \{f, i, j\}.
- With no cycle it would be a forest with some c \ge 1 components and n - c \le n - 1 edges (Result 4), fewer than n. Example: the triangle 12, 13, 23 and the path 34, 45, 56, 67, 78, with 3 + 5 = 8 edges. Removing any one path edge disconnects the graph, so by the fact in the proof of Result 7 none lies on a cycle: the triangle is the only one.
- A cycle of T - v would be one of T. For w \ne v, the path from w to v reaches v from a neighbor x_i, so w is joined to x_i in T - v: at most d components. For neighbors x_i \ne x_j the only path in T is (x_i, v, x_j), so they are not joined in T - v: exactly d. \square
- An edge on a cycle could be removed keeping the graph connected (the fact in the proof of Result 7), so it has no cycle, and being connected it is a tree. \square
- If u, v were in different components, they are not adjacent, and a cycle of G + uv would need a path from v to u in G. So G is connected, and a tree. \square
- The walk contains a path from u to v made of its edges (Walks, paths, cycles and connected graphs, Result 1), and by Result 5 that is the path from u to v. \square
- 6. A connected network on 26 towns keeps at least 25 roads (Result 8), so at most 31 - 25 = 6 close, and removing roads on cycles reaches 25. What is left is a tree.
- At least 9, since 31 \ge 40 - c (Result 8). Exactly 9 when it has no cycle, since then it is a forest with 40 - 31 = 9 components.
- 27 atoms and \displaystyle \frac{4 \cdot 9 + 18}{2} = 27 bonds, more than the 26 of a tree, so the connected graph has a cycle by Result 7. (Cyclononane is such a ring.)
- 2 \cdot 7 + 2 = 16 hydrogens, 23 atoms and 22 bonds. Only the two end carbons have one carbon neighbor, so 2, and 2 \cdot 3 + 5 \cdot 2 = 16.
- n_1 = 2 + 1 \cdot 4 + 3 \cdot 2 = 12 leaves, 4 + 2 + 12 = 18 vertices.
- n_1 = n_3 + 2 and n_1 + n_3 = 20 give 9 of degree 3 and 11 leaves. Always n = 2n_3 + 2, which is even.
- A triangle and a separate edge: 5 vertices, 4 edges, no isolated vertex, a cycle.
- Level 0: f; level 1: c, i, j; level 2: a; level 3: b; level 4: d, e; level 5: g, h. The parent of a is c, the children of b are d, e, and the height is 5. Root a gives height 3, the least: d(g, i) = 6 \le d(g, r) + d(r, i), so from any root r one of g, i is at level at least 3.
- 6^{4} = 1296. Removing leaf 5 leaves a labeled tree on \{1, 2, 3, 4\} (Result 2), from one of whose 4 vertices 5 hangs; the 16 \cdot 4 = 64 choices give different trees and every such tree arises.
- The 3 stars with center 2, 3 or 4, and the 3! = 6 paths (1, x, y, z): 9 in all. The method of Exercise 19 gives 3 \cdot 3 = 9.
- For k \le 2, Result 1 gives two leaves. For k \ge 3, Result 9 gives n_1 \ge 2 + (k - 2) = k. \square
- By induction on n; for n = 2 the single edge 12 works. For n \ge 3 some d_i = 1 (else the sum is at least 2n) and some d_j \ge 2 (else it is n < 2n - 2). Dropping d_i and lowering d_j by 1 leaves n - 1 positive integers with sum 2n - 4 = 2(n - 1) - 2; a tree on the other n - 1 labels with those degrees exists by hypothesis (after renaming labels), and joining i to j adds a leaf, which keeps a tree and finishes. \square
- Both children are on level L + 1 if the parent is on level L, and by Result 10 the ends of an edge differ by one level. \square