7.4: Trees
- Page ID
- 182005
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\dsum}{\displaystyle\sum\limits} \)
\( \newcommand{\dint}{\displaystyle\int\limits} \)
\( \newcommand{\dlim}{\displaystyle\lim\limits} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\(\newcommand{\longvect}{\overrightarrow}\)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)- Describe and identify trees.
- Determine a minimum spanning tree for a connected graph.
- Solve application problems involving trees.
We saved the best for last! In this last section, we will discuss arguably the most fun kinds of graphs and trees. Have you ever researched your family tree? Family trees are a perfect example of the kind of trees we study in graph theory. One of the characteristics of a family tree graph is that it never loops back around because no one is their own grandparent!
What Is A Tree?
Whether we are talking about a family tree or a tree in a forest, none of the branches ever loops back around and rejoins the trunk. This means that a tree has no cyclic subgraphs or is acyclic. A tree also has only one component. So, a tree is a connected acyclic graph. Here are some graphs that have the same characteristics. Each of the graphs in figure and figure are a tree.
Applications of Tree Graphs
Tree structures appear everywhere because they efficiently organize information. Here are the most common and important uses:
- Folders and subfolders on a computer form a tree.
-
Communication networks
-
Shows relationships between generations.
-
Company Organization Chart
-
There are no loops or closed paths.
-
Every pair of vertices is connected by exactly one path.
-
The number of edges is one less than the number of vertices. If tree has \(n\) vertices, It must have \(n-1\) edges.
-
Every edge in a tree is a bridge.
Example \(\PageIndex{2}\): Identifying Trees
Identify any trees in Figure \(\PageIndex{4}.\) If a graph is not a tree, explain how you know.
- Answer
-
Graph M is not a tree because it contains the cycle (b, c, f).
Graph N is not a tree because it is not connected. It has two components, one with vertices h, i, j, and another with vertices k, l, m.
Graph P is a tree. It has no cycles, and it is connected.
Example \(\PageIndex{3}\): Exploring Characteristics of Trees
Use Graphs I and J in Figure \(\PageIndex{5}\) to answer each question.
Figure \(\PageIndex{5}:\) Graphs I and J
\(1.\) Which vertices are in each of the components that remain when edge be is removed from Graph I?
\(2.\) Determine the number of edges and the number of vertices in Graph J. Explain how this confirms that Graph J is a tree.
\(3.\) What kind of cycle is created if edge im is added to Graph J?
- Answer
-
\(1.\) When edge be is removed, there are two components that remain. One component includes vertices a, b, and c. The other component includes vertices d, e, and f.
\(2.\) There are seven vertices and six edges in Graph J. This confirms that Graph J is a tree because the number of edges is one less than the number of vertices.
\(3.\) The pentagon (i, h, j, l, m) is created when edge im is added to Graph J.
In the 1997 film Good Will Hunting, the main character, Will, played by Matt Damon, solves what is supposed to be an exceptionally difficult graph theory problem, “Draw all the homeomorphically irreducible trees of size
Spanning Trees
Suppose that you planned to set up your own computer network with four devices. One option is to use a “mesh topology” like the one in Figure in which each device is connected directly to every other device in the network.
The mesh topology for four devices could be represented by the complete Graph A1 in Figure where the vertices represent the devices, and the edges represent network connections. However, the devices could be networked using fewer connections. Graphs A2, A3, and A4 of Figure configurations in which three of the six edges have been removed. Each of the Graphs A2, A3 and A4 in Figure is a tree because it is connected and contains no cycles. Since Graphs A2, A3, and A4 are also subgraphs of Graph A1 that include every vertex of the original graph, they are also known as spanning trees.
By definition, spanning trees must span the whole graph by visiting all the vertices. Since spanning trees are subgraphs, they may only have edges between vertices that were adjacent in the original graph. Since spanning trees are trees, they are connected, and they are acyclic.
So, when deciding whether a graph is a spanning tree, check the following characteristics:
- All vertices are included.
- No vertices are adjacent that were not adjacent in the original graph.
- The graph is connected.
- There are no cycles.
What is a Spanning Tree?
A spanning tree of a graph is a sub-graph that includes all the vertices of the original graph and has no cycles (because it is a tree).
Why use a Spanning Tree?
Because it connects all points with no redundancy and uses the least number of edges, it is used in:
- Designing efficient communication networks
- Reducing the cost of wiring or cabling
- Optimizing routes in transportation
Example \(\PageIndex{4}\): Identifying Spanning Trees
Use Figure \(\PageIndex{8}\) to determine which of graphs M1, M2, M3, and M4, are spanning trees of Q.
- Answer
-
\(1.\) Graph M1 is not a spanning tree of Graph Q because it has a cycle (c, d, f, e).
\(2.\) Graph M2 is a spanning tree of Graph Q because it has all the original vertices, no vertices are adjacent in M2 that weren’t adjacent in Graph Q, Graph M2 is connected, and it contains no cycles.
\(3.\) Graph M3 is not a spanning tree of Graph Q because vertices a and f are adjacent in Graph M3 but not in Graph Q.
\(4.\) Graph M4 is not a spanning tree of Graph Q because it is not connected.
So, only graph M2 is a spanning tree of Graph Q.
Constructing a Spanning Tree Using Paths
Suppose that you wanted to find a spanning tree within a graph. One approach is to find paths within the graph. You can start at any vertex, go any direction, and create a path through the graph, stopping only when you can’t continue without backtracking, as shown in Figure
Once you have stopped, pick a vertex along the path you drew as a starting point for another path. Make sure to visit only the vertices you have not visited before, as shown in Figure
Repeat this process until all vertices have been visited as shown in Figure
The end result is a tree that spans the entire graph as shown in Figure
Notice that this subgraph is a tree because it is connected and acyclic. It also visits every vertex of the original graph, so it is a spanning tree. However, it is not the only spanning tree for this graph. By making different turns, we could create any number of distinct spanning trees.
Revealing Spanning Trees
Another approach to finding a spanning tree in a connected graph involves removing unwanted edges to reveal a spanning tree. Consider Graph D in Figure
Graph D has \(10\) vertices. A spanning tree of Graph D must have \(9\) edges, because the number of edges is one less than the number of vertices in any tree. Graph D has \(13\) edges so \(4\) need to be removed. To determine which \(4\) edges to remove, remember that trees do not have cycles. There are four triangles in Graph D that we need to break up. We can accomplish this by removing \(1\) edge from each of the triangles. There are many ways this can be done. Two of these ways are shown in Figure
Example \(\PageIndex{5}\): Removing Edges to Find Spanning Trees
Use the graph in Figure \(\PageIndex{15}\) to answer each question.
\(1.\) Determine the number of edges that must be removed to reveal a spanning tree.
\(2.\) Name all the undirected cycles in Graph V.
\(3.\) Find two distinct spanning trees of Graph V.
- Answer
-
\(1.\) Graph V has nine vertices, so a spanning tree for the graph must have 8 edges. Since Graph V has \(11\) edges, \(3\) edges must be removed to reveal a spanning tree.
\(2.\) (a, c, d), (a, c, f), (a, d, c, f), and (b, e, h, i, g)
\(3.\) To find the first spanning tree, remove edge ac, which will break up both of the triangles, remove edge cf, which will break up the quadrilateral, and remove be, which will break up the pentagon, to give us the spanning tree shown in Figure \(\PageIndex{16}.\)
Figure \(\PageIndex{16}:\) Spanning Tree Formed Removing ac, cf, and be To find another spanning tree, remove ad, which will break up (a, c, d) and (a, d, c, f), remove af to break up (a, c, f), and remove hi to break up (b, e, h, i, g). This will give us the spanning tree in Figure \(\PageIndex{17}.\)
Figure \(\PageIndex{17}:\) Spanning Tree Formed Removing ad, af, and hi
Construct two distinct spanning trees for the graph in Figure \(\PageIndex{18}.\)
- Answer
-
Two possible solutions are given in Figure \(\PageIndex{19}\) and Figure \(\PageIndex{20}.\)
Figure \(\PageIndex{19}:\) First Spanning Tree for Graph L Figure \(\PageIndex{20}:\) Second Spanning Tree for Graph L
Minimum Spanning Tree (MST) and Kruskal’s Algorithm
In many applications of spanning trees, the graphs are weighted, and we want to find the spanning tree of the least possible weight. For example, the graph might represent a computer network, and the weights might represent the cost involved in connecting two devices. So, finding a spanning tree with the lowest possible total weight, or minimum spanning tree, means saving money! The method that we will use to find a minimum spanning tree (MST) of a weighted graph is called Kruskal’s algorithm. The steps for Kruskal’s algorithm are:
Step 1: Choose any edge with the minimum weight of all edges.
Step 2: Choose another edge of minimum weight from the remaining edges. The second edge does not have to be connected to the first edge.
Step 3: Choose another edge of minimum weight from the remaining edges, but do not select any edge that creates a cycle in the subgraph you are creating.
Step 4: Repeat step \(3\) until all the vertices of the original graph are included and you have a spanning tree.
Where is MST used?
MSTs help design networks that connect all nodes at the minimum cost. Some examples include
- Cable TV distribution networks, Internet wiring, fiber-optic networks, Telephone and communication networks
- Electrical power grids
- Cheapest road connections between cities, Railway routes, Pipeline networks (water, gas, oil)
- Airline route optimization (connecting hubs with minimal cost)
Example \(\PageIndex{6}:\) Using Kruskal’s Algorithm
A computer network will be set up with six devices. The vertices in the graph in Figure \(\PageIndex{21}\) represent the devices, and the edges represent the cost of a connection. Find the network configuration that will cost the least. What is the total cost?
- Answer
-
A minimum spanning tree will correspond to the network configuration of the least cost. We will use Kruskal’s algorithm to find one. Since the graph has six vertices, the spanning tree will have six vertices and five edges.
Step 1: Choose an edge of least weight. We have sorted the weights into numerical order. The least is \($100.\) The only edge of this weight is edge AF as shown in Figure \(\PageIndex{22}.\)
Figure \(\PageIndex{22}:\) Step 1 Select Edge AF Step 2: Choose the edge of least weight of the remaining edges, which is BD with \($120\) Notice that the two selected edges do not need to be adjacent to each other as shown in Figure \(\PageIndex{23}.\)
Figure \(\PageIndex{23}:\) Step 2 Select Edge BD Step 3: Select the lowest weight edge of the remaining edges, as long as it does not result in a cycle. We select DF with \($150\) since it does not form a cycle as shown in Figure \(\PageIndex{24}.\)
Figure \(\PageIndex{24}\): Step 3 Select Edge DF Repeat Step 3: Select the lowest weight edge of the remaining edges, which is BE with \($160\) and it does not form a cycle as shown in Figure \(\PageIndex{25}.\) This gives us four edges so we only need to repeat step 3 once more to get the fifth edge.
Figure \(\PageIndex{25}:\) Repeat Step 3 Select Edge DF Repeat Step 3: The lowest weight of the remaining edges is \($170.\) Both BF and CE have a weight of \($170,\) but BF would create cycle (b, d, f) and there cannot be a cycle in a spanning tree as shown in Figure \(\PageIndex{26}.\)
Figure \(\PageIndex{26}:\) Repeat Step 3 Do Not Select Edge BF So, we will select CE, which will complete the spanning tree as shown in Figure \(\PageIndex{27}.\)
Figure \(\PageIndex{27}:\) Repeat Step 3 Select Edge CE The minimum spanning tree is shown in Figure \(\PageIndex{28}.\) This is the configuration of the network of least cost. The spanning tree has a total weight of , which is the total cost of this network configuration.
Figure \(\PageIndex{28}:\) Final Minimum Spanning Tree


