The Theory of Computation

Bernard M.E. Moret

Addison-Wesley-Longman, 1998


Detailed Solutions

Chapter 2, Problem 1




Prove that any tree must have one more vertex than it has edges.

We need to show that a tree, that is, an acyclic connected (undirected and finite) graph, that has n>0 vertices must have exactly n-1 edges.

We actually prove first that any acyclic graph must have at least one vertex of degree less than 2 -- consider this to be a lemma -- and then prove that any acyclic connected graph with n vertices and at least one vertex of degree less than 2 has n-1 edges.

So let us address the lemma: a graph G cannot be acyclic if all of its vertices have degree at least 2. We prove this assertion by induction on n, the number of vertices of the graph. The lemma is vacuously true for graphs with one vertex or two vertices, since a degree of 2 is not possible in such graphs. (A vacuous basis is one that is true through the implication "false => true" -- the assumptions made in the statement of the theorem do not hold, so the implication is valid. Our theorem states "if all vertices of a graph have degree at least 2, then the graph has a cycle" and, in our two base cases (1 or 2 vertices), the highest degree possible for a vertex is 1, so that the hypothesis is false and thus the implication is valid.) If you dislike vacuous bases, consider a graph on 3 vertices where every vertex has degree 2 (no higher degree is possible): there is only one such graph, the complete graph on 3 vertices, K3, and it has a cycle.

Assume then that such is true of all graphs of up to n-1 vertices and consider a graph G of n vertices where all vertices have degree at least 2. Let v be a vertex of lowest degree (which is at least 2) and u and w be two vertices to which v is connected. Two cases arise. If there is an edge between u and w, then G has a cycle (the three vertices u, v, and w form a cycle), as desired. If there is no edge in G between u and w, consider the new graph G' obtained from G by removing vertex v from G and adding the edge from u to w. G' has n-1 vertices, all of degree 2 or higher, and thus obeys the inductive hypothesis, so that it has a cycle. If this cycle does not involve the edge {u,w}, it is also present in G and we are done. If the cycle uses edge {u,w}, then G has almost the same cycle, in which the edge {u,w} (which does not exist in G) is replaced by the two edges {u,v} and {v,w}.

Our lemma tells us that any tree must have at least one vertex of degree less than 2. We shall use this fact in proving that trees must have one more vertex than they have edges. We proceed by induction on the number n of vertices of the tree. The basis is true: a graph of n=1 vertices cannot have any edges and is acyclic and connected by default. (This is not a vacuous basis, because the hypothesis does apply, but you could certainly argue that it does not display the claimed properties very clearly. If you dislike starting with such a basis, consider a graph of n=2 vertices: the two vertices must be connected by an edge for the graph to be connected and that is the only edge possible, so we have 1 edge and 2 vertices, thereby obeying the conclusion.) Assume then that all trees on n-1 or fewer vertices obey the theorem (the inductive hypothesis) and consider a tree G=(V,E) of n vertices. Let v be a vertex of G of degree less than 2 (which must exist by our lemma) and consider the graph G' obtained by removing from G the vertex v and its associated edge (if any). Note that G' is connected, acyclic, and has n-1 vertices; thus, by our lemma, it must contain a vertex of degree less than 2. Thus G' obeys the inductive hypothesis and thus has n-2 edges, so that G must have n-1 edges, as desired, and we are done.

This two-step proof is actually fairly tricky. A direct induction on the number of vertices either is quite complex or fails because of insufficient knowledge about the vertex involved in the inductive step. By separating into two cases the status of that vertex (and generalizing a bit to obtain our lemma, which does not mention connectedness), we were able to reduce the complexity of each case, turning each of lemma and theorem into fairly straightforward induction proofs.