Login
📚 Discrete Mathematics
Chapters ▾
⇩ Download ▾

5.2 Trees

One very useful and common approach to studying graph theory is to restrict your focus to graphs of a particular kind. For example, you could try to really understand just complete graphs or just bipartite graphs, instead of trying to understand all graphs in general. That is what we are going to do now, looking at trees. Hopefully by the end of this section we will have a better understanding of this class of graph, and also understand why it is important enough to warrant its own section.

Does the definition above agree with your intuition for what graphs we should call trees? Try thinking of examples of trees and make sure they satisfy the definition. One thing to keep in mind is that while the trees we study in graph theory are related to trees you might see in other subjects, the correspondence is not exact. For instance, in anthropology, you might study family trees, like the one below,

A family tree with "Me" at the top, branching down to the left to "Mom" and to the right to "Dad". "Mom" has branches leading down to "Maternal Grandma" and "Maternal Grandpa". "Dad" has branches down to "Paternal Grandma" and "Paternal Grandpa".

So far so good, but while your grandparents are (probably) not blood-relatives, if we go back far enough, it is likely that they did have some common ancestor. If you trace the tree back from you to that common ancestor, then down through your other grandparent, you would have a cycle, and thus the graph would not be a tree.

You might also have seen something called a decision tree (such as the algorithm for deciding whether a series converges or diverges). Sometimes these too contain cycles, as the decision for one node might lead you back to a previous step.

Both the examples of trees above also have another feature worth mentioning: there is a clear order to the vertices in the tree. In general, there is no reason for a tree to have this added structure, although we can impose such a structure by considering rooted trees, where we simply designate one vertex as the root. We will consider such trees in more detail later in this section.

Properties of Trees

We wish to really understand trees. This means we should discover properties of trees; what makes them special and what is special about them.

A tree is a connected graph with no cycles. Is there anything else we can say? It would be nice to have other equivalent conditions for a graph to be a tree. That is, we would like to know whether there are any graph theoretic properties that all trees have, and perhaps even that only trees have.

To get a feel for the sorts of things we can say, we will consider three propositions about trees. These will also illustrate important proof techniques that apply to graphs in general, and happen to be a little easier for trees.

Our first proposition gives an alternate definition for a tree. That is, it gives necessary and sufficient conditions for a graph to be a tree.

Read the proof above very carefully. Notice that both directions had two parts: the existence of paths, and the uniqueness of paths (which related to the fact that there were no cycles). In this case, these two parts were really separate. In fact, if we just considered graphs with no cycles (a forest), then we could still do the parts of the proof that explore the uniqueness of paths between vertices, even if there might not exist paths between vertices.

This observation allows us to state the following corollary:2

We do not give a proof of the corollary (it is, after all, supposed to follow directly from the proposition) but for practice, you are asked to give a careful proof in the exercises. When you do so, try to use proof by contrapositive instead of proof by contradiction.

Our second proposition tells us that all trees have leaves: vertices of degree one.

The proposition is quite useful when proving statements about trees, because we often prove statements about trees by induction. To do so, we need to reduce a given tree to a smaller tree (so we can apply the inductive hypothesis). Getting rid of a vertex of degree one is an obvious choice, and now we know there is always one to get rid of.

To illustrate how induction is used on trees, we will consider the relationship between the number of vertices and number of edges in trees. Is there a tree with exactly 7 vertices and 7 edges? Try to draw one. Could a tree with 7 vertices have only 5 edges? There is a good reason that these seem impossible to draw.

There is a very important feature of this induction proof that is worth noting. Induction makes sense for proofs about graphs because we can think of graphs as growing into larger graphs. However, this does NOT work. It would not be correct to start with a tree with k vertices, and then add a new vertex and edge to get a tree with k + 1 vertices, and note that the number of edges also grew by one. Why is this bad? Because how do you know that every tree with k + 1 vertices is the result of adding a vertex to your arbitrary starting tree? You don't!

The point is that whenever you give an induction proof that a statement about graphs that holds for all graphs with v vertices, you must start with an arbitrary graph with v + 1 vertices, then reduce that graph to a graph with v vertices, to which you can apply your inductive hypothesis.

Rooted Trees

So far, we have thought of trees only as a particular kind of graph. However, it is often useful to add additional structure to trees to help solve problems. Data is often structured like a tree. This book, for example, has a tree structure: draw a vertex for the book itself. Then draw vertices for each chapter, connected to the book vertex. Under each chapter, draw a vertex for each section, connecting it to the chapter it belongs to. The graph will not have any cycles; it will be a tree. But a tree with clear hierarchy which is not present if we don't identify the book vertex as the “top”.

As soon as one vertex of a tree is designated as the root, then every other vertex on the tree can be characterized by its position relative to the root. This works because there is a unique path between any two vertices in a tree. So from any vertex, we can travel back to the root in exactly one way. This also allows us to describe how distinct vertices in a rooted tree are related.

If two vertices are adjacent, then we say one of them is the parent of the other, which is called the child of the parent. Of the two, the parent is the vertex that is closer to the root. Thus the root of a tree is a parent, but is not the child of any vertex (and is unique in this respect: all non-root vertices have exactly one parent).

Not surprisingly, the child of a child of a vertex is called the grandchild of the vertex (and it is the grandparent). More in general, we say that a vertex v is a descendent of a vertex u provided u is a vertex on the path from v to the root. Then we would call u an ancestor of v .

For most trees (in fact, all except paths with one end the root), there will be pairs of vertices neither of which is a descendant of the other. We might call these cousins or siblings. In fact, vertices u and v are called siblings provided they have the same parent. Note that siblings are never adjacent (do you see why?).

All of this flowery language helps us describe how to navigate through a tree. Traversing a tree, visiting each vertex in some order, is a key step in many algorithms. Even if the tree is not rooted, we can always form a rooted tree by picking any vertex as the root. Here is an example of why doing so can be helpful.

The key to how we partitioned the tree in the example was to know which vertex to assign to a set next. We chose to visit all vertices in the same generation before any vertices of the next generation. This is usually called a breadth first search (we say “search” because you often traverse a tree looking for vertices with certain properties).

In contrast, we could also have partitioned the tree in a different order. Start with the root, put it in A . Then look for one child of the root to put in B . Then find a child of that vertex, into A , and then find its child, into B , and so on. When you get to a vertex with no children, retreat to its parent and see if the parent has any other children. So we travel as far from the root as fast as possible, then backtrack until we can move forward again. This is called depth first search.

These algorithmic explanations can serve as a proof that every tree is bipartite, although care needs to be spent to prove that the algorithms are correct. Another approach to prove that all trees are bipartite, using induction, is requested in the exercises.

Spanning Trees

One of the advantages of trees is that they give us a few simple ways to travel through the vertices. If a connected graph is not a tree, then we can still use these traversal algorithms if we identify a subgraph that is a tree.

First we should consider if this even makes sense. Given any connected graph G , will there always be a subgraph that is a tree? Well, that is actually too easy: you could just take a single vertex of G . If we want to use this subgraph to tell us how to visit all vertices, then we want our subgraph to include all of the vertices. We call such a tree a spanning tree. It turns out that every connected graph has one (and usually many).

How do we know? We can give an algorithm for finding a spanning tree! Start with a connected graph G . If there is no cycle, then G is already a tree and we are done. If there is a cycle, let e be any edge in that cycle and consider the new graph G 1 = G e (i.e., the graph you get by deleting e ). This tree is still connected since e belonged to a cycle, there were at least two paths between its incident vertices. Now repeat: if G 1 has no cycles, we are done, otherwise define G 2 to be G 1 e 1 , where e 1 is an edge in a cycle in G 1 . Keep going. This process must eventually stop, since there are only a finite number of edges to remove. The result will be a tree, and since we never removed any vertex, a spanning tree.

This is by no means the only algorithm for finding a spanning tree. You could have started with the empty graph and added edges that belong to G as long as adding them would not create a cycle. You have some choices as to which edges you add first: you could always add an edge adjacent to edges you have already added (after the first one, of course), or add them using some other order. Which spanning tree you end up with depends on these choices.

Although we will not consider this in detail, these algorithms are usually applied to weighted graphs. Here every edge has some weight or cost assigned to it. The goal is to find a spanning tree that has the smallest possible combined weight. Such a tree is called a minimum spanning tree. Finding the minimum spanning tree uses basically the same algorithms as we described above, but when picking an edge to add, you always pick the smallest (or when removing an edge, you always remove the largest).3

Which of the following graphs are trees?

  1. G = ( V , E ) with V = { a , b , c , d , e } and E = { { a , b } , { a , e } , { b , c } , { c , d } , { d , e } }
  2. G = ( V , E ) with V = { a , b , c , d , e } and E = { { a , b } , { b , c } , { c , d } , { d , e } }
  3. G = ( V , E ) with V = { a , b , c , d , e } and E = { { a , b } , { a , c } , { a , d } , { a , e } }
  4. G = ( V , E ) with V = { a , b , c , d , e } and E = { { a , b } , { a , c } , { d , e } }
  1. This is not a tree since it contains a cycle. Note also that there are too many edges to be a tree, since we know that all trees with v vertices have v 1 edges.
  2. This is a tree since it is connected and contains no cycles (which you can see by drawing the graph). All paths are trees.
  3. This is a tree since it is connected and contains no cycles (draw the graph). All stars are trees.
  4. This is a not a tree since it is not connected. Note that there are not enough edges to be a tree.

For each degree sequence below, decide whether it must always, must never, or could possibly be a degree sequence for a tree. Remember, a degree sequence lists out the degrees (number of edges incident to the vertex) of all the vertices in a graph in non-increasing order.

  1. ( 4 , 1 , 1 , 1 , 1 )
  2. ( 3 , 3 , 2 , 1 , 1 )
  3. ( 2 , 2 , 2 , 1 , 1 )
  4. ( 4 , 4 , 3 , 3 , 3 , 2 , 2 , 1 , 1 , 1 , 1 , 1 , 1 , 1 )
  1. This must be the degree sequence for a tree. This is because the vertex of degree 4 must be adjacent to the four vertices of degree 1 (there are no other vertices for it to be adjacent to), and thus we get a star.
  2. This cannot be a tree. Each degree 3 vertex is adjacent to all but one of the vertices in the graph. Thus each must be adjacent to one of the degree 1 vertices (and not the other). That means both degree 3 vertices are adjacent to the degree 2 vertex, and to each other, so that means there is a cycle.
    Alternatively, count how many edges there are!
  3. This might or might not be a tree. The length 4 path has this degree sequence (this is a tree), but so does the union of a 3-cycle and a length 1 path (which is not connected, so not a tree).
  4. This cannot be a tree. The sum of the degrees is 28, so there are 14 edges. But there are 14 vertices as well, so we don't have v = e + 1 , meaning this cannot be a tree.

For each degree sequence below, decide whether it must always, must never, or could possibly be a degree sequence for a tree. Justify your answers.

  1. ( 3 , 3 , 2 , 2 , 2 )
  2. ( 3 , 2 , 2 , 1 , 1 , 1 )
  3. ( 3 , 3 , 3 , 1 , 1 , 1 )
  4. ( 4 , 4 , 1 , 1 , 1 , 1 , 1 , 1 )

Careful: the graphs might not be connected.

Suppose you have a graph with v vertices and e edges that satisfies v = e + 1 . Must the graph be a tree? Prove your answer.

Try Exercise.

Prove that any graph (not necessarily a tree) with v vertices and e edges that satisfies v > e + 1 will NOT be connected.

Try a proof by contradiction and consider a spanning tree of the graph.

If a graph G with v vertices and e edges is connected and has v < e + 1 , must it contain a cycle? Prove your answer.

Yes. We will prove the contrapositive. Assume G does not contain a cycle. Then G is a tree, so would have v = e + 1 , contrary to stipulation.

We define a forest to be a graph with no cycles.

  1. Explain why this is a good name. That is, explain why a forest is a union of trees.
  2. Suppose F is a forest consisting of m trees and v vertices. How many edges does F have? Explain.
  3. Prove that any graph G with v vertices and e edges that satisfies v < e + 1 must contain a cycle (i.e., not be a forest).

For part (b), trying some simple examples should give you the formula. Then you just need to prove it is correct.

Give a careful proof of Corollary: A graph is a forest if and only if there is at most one path between any pair of vertices. Use proof by contrapositive (and not a proof by contradiction) for both directions.

Examining the proof of Proposition gives you most of what you need, but make sure to just give the relevant parts, and take care to not use proof by contradiction.

Give a careful proof by induction on the number of vertices, that every tree is bipartite.

You will need to remove a vertex of degree one, apply the inductive hypothesis to the result, and then say which set the degree one vertex to.

Consider the tree drawn below.

A labeled tree with nine vertices labeled a through h. Vertices a, b, e, f, and i are on a single row, adjacent on a path in that order from left to right. Vertex b is adjacent to c and d above it. Vertex f is adjacent to g and h about it.
  1. Suppose we designate vertex e as the root. List the children, parents and siblings of each vertex. Does any vertex other than e have grandchildren?
  2. Suppose e is not chosen as the root. Does our choice of root vertex change the number of children e has? The number of grandchildren? How many are there of each?
  3. In fact, pick any vertex in the tree and suppose it is not the root. Explain why the number of children of that vertex does not depend on which other vertex is the root.
  4. Does the previous part work for other trees? Give an example of a different tree for which it holds. Then either prove that it always holds or give an example of a tree for which it doesn't.

If e is the root, then b will have three children ( a , c , and d ), all of which will be siblings, and have b as their parent. a will not have any children.

In general, how can you determine the number of children a vertex will have, if it is not a root?

Let T be a rooted tree that contains vertices u , v , and w (among possibly others). Prove that if w is a descendant of both u and v , then u is a descendant of v or v is a descendant of u .

Unless it is already a tree, a given graph G will have multiple spanning trees. How similar or different must these be?

  1. Must all spanning trees of a given graph be isomorphic to each other? Explain why or give a counterexample.
  2. Must all spanning trees of a given graph have the same number of edges? Explain why or give a counterexample.
  3. Must all spanning trees of a graph have the same number of leaves (vertices of degree 1)? Explain why or give a counterexample.
  1. No, although there are graphs for which this is true. For example, K 4 has a spanning tree that is a path (of three edges) and also a spanning tree that is a star (with center vertex of degree 3).
  2. Yes. For a fixed graph, we have a fixed number v of vertices. Any spanning tree of the graph will also have v vertices, and since it is a tree, must have v 1 edges.
  3. No, although there are graph for which this is true (note that if all spanning trees are isomorphic, then all spanning trees will have the same number of leaves). Again, K 4 is a counterexample. One spanning tree is a path, with only two leaves, another spanning tree is a star with 3 leaves.

Find all spanning trees of the graph below. How many different spanning trees are there? How many different spanning trees are there up to isomorphism (that is, if you grouped all the spanning trees by which are isomorphic, how many groups would you have)?

A graph with six vertices labeled a through f. Vertices a, b, and c form a triangle (with their edges), with a directly above b and c to the right of both. Vertex c is then adjacent to vertices d, f, and e, with d directly above f and e farther to the right. Vertices d and f are also adjacent to e.

Give an example of a graph that has exactly 7 different spanning trees. Note, it is acceptable for some or all of these spanning trees to be isomorphic.

There is an example with 7 edges.

Prove that every connected graph which is not itself a tree must have at last three different (although possibly isomorphic) spanning trees.

The previous exercise will be helpful.

Consider edges that must be in every spanning tree of a graph. Must every graph have such an edge? Give an example of a graph that has exactly one such edge.

Note that such an edge, if removed, would disconnect the graph. We call graphs that have an edge like this 1-connected.

Discrete Mathematics: An Open Introduction, 3rd edition, by Oscar Levin (discrete.openmathbooks.org), licensed under CC BY-SA 4.0; this adaptation is distributed under the same license. License: CC-BY-SA-4.0.