CHAPTER 15
Graph Theory
© 2010 Pearson Prentice Hall. All rights reserved.
15.4
Trees
© 2010 Pearson Prentice Hall. All rights reserved.
2
Objectives
1. Understand the definition and properties of a tree.
2. Find a spanning tree for a connected graph.
3. Find the minimum spanning tree for a weighted
graph.
© 2010 Pearson Prentice Hall. All rights reserved.
3
Trees
A tree is a graph that is connected and has no circuits.
All trees have the following properties:
1. There is one and only one path joining any two
vertices.
2. Every edge is a bridge.
3. A tree with n vertices must have n – 1 edges.
© 2010 Pearson Prentice Hall. All rights reserved.
4
Example 1: Identifying Trees
Which of the following graphs are trees? Why or why
not?
Not a tree because
it is disconnected,
i.e., a tree with five
vertices must have
four edges.
A tree because it is
connected, i.e., there is
only one path joining
any two vertices. If any
edge is removed, then
the graph would be
disconnected.
© 2010 Pearson Prentice Hall. All rights reserved.
Not a tree because
it has a circuit, i.e.,
a tree with five
vertices must have
four edges and
there are five
vertices and five
edges.
5
Spanning Trees
• A subgraph is a set of vertices and edges chosen
from among those of the original graph.
• A subgraph that contains all of a connected graph’s
vertices, is connected, and contains no circuits is
called a spanning tree.
• The two subgraphs in the previous example are
spanning trees.
© 2010 Pearson Prentice Hall. All rights reserved.
6
Example 2: Finding a Spanning Tree
Find a spanning tree for the graph.
Solution: A possible spanning tree must contain all eight
vertices shown in the connected graph above. The
spanning tree must have 8 – 1 = 7 edges.
• Since the previous graph has 12 edges, we must
remove 5 edges.
© 2010 Pearson Prentice Hall. All rights reserved.
7
Example 2: Finding a Spanning Tree
Solution:
We break the inner rectangular circuit
removing edge FG.
• We break the outer rectangular
circuit by removing all four of its
edges while retaining the edges leading to vertices A,
B, C, and D.
This leaves us the spanning tree seen on the right.
Notice that each edge is a bridge and no circuits are
present.
© 2010 Pearson Prentice Hall. All rights reserved.
8
Minimum Spanning Trees
• The minimum spanning tree for a weighted graph is
a spanning tree with the smallest possible total
weight.
From the spanning trees below, we see (c) has a smaller
weight than (b), but is this the minimum spanning
tree or should we continue to find other possible
spanning trees that may have a total weight less than
107?
© 2010 Pearson Prentice Hall. All rights reserved.
9
Kruskal’s Algorithm
Here is a procedure for finding the minimum spanning
tree from a weighted graph:
1. Find the edge with the smallest weight in the graph.
If there is more than one, pick one at random. Mark
it in red.
2. Find the next-smallest edge in the graph. If there is
more than one, pick one at random. Mark it in red.
3. Find the next-smallest unmarked edge in the graph
that does not create a red circuit. If there is more
than one, pick one at random. Mark it in red.
4. Repeat step 3 until all vertices have been included.
The red edges are the desired minimum spanning
tree.
© 2010 Pearson Prentice Hall. All rights reserved.
10
Example 3: Using Kruskal’s Algorithm
Seven buildings on a college are connected by the
sidewalks shown in the figure.
The weighted graph represents buildings as vertices,
sidewalks as edges, and sidewalk lengths as weights.
A heavy snow has fallen and the sidewalks need to be
cleared quickly. Campus decides to clear as little as
possible and still ensure that students walking from
building to building will be able to do so along cleared
paths.
Determine the shortest series of sidewalks to clear. What
is the total length of the sidewalks that need to be
cleared?
© 2010 Pearson Prentice Hall. All rights reserved.
11
Example 3: Using Kruskal’s Algorithm
Using Kruskal’s Algorithm, we complete minimizing
the spanning tree in a series of steps given below.
Refer to the next graph coinciding with the steps.
© 2010 Pearson Prentice Hall. All rights reserved.
12
Example 3: Using Kruskal’s Algorithm
Step 1. Find the edge with the smallest weight. Select edge GF by
marking it in red.
Step 2. Find the next-smallest edge
in the graph. Select BD by
marking it in red.
Step 3. Find the next-smallest edge
in the graph. Select AD by
marking it in red.
Step 4. Find the next-smallest edge
in the graph that does not create a circuit. Select DG, since it
does not create a circuit, by marking it in red.
© 2010 Pearson Prentice Hall. All rights reserved.
13
Example 3: Using Kruskal’s Algorithm
Step 5. Find the next-smallest edge in the
graph that does not create a circuit.
Select CD, since it does not create
a circuit, by marking it in red.
Step 6. Find the next-smallest edge
in the graph that does not create
a circuit. Select CE, since it does
not create a circuit, by marking it in red.
The minimum spanning tree is completed. The red subgraph
contains all seven vertices, six edges, and no circuits.
© 2010 Pearson Prentice Hall. All rights reserved.
14
Example 3: Using Kruskal’s Algorithm
The total length of the sidewalks that need to be cleared is
242 + 245 + 249 + 251 + 253 + 259,
or 1499 feet.
© 2010 Pearson Prentice Hall. All rights reserved.
15