1
MATH 301: DISCRETE MATHEMATICS
Chapter-11: Trees
Copyright © Nahid Sultana 2016-2017.
5/16/2025
Chapter Summary
2
o Introduction to Trees
o Applications of Trees
o Tree Traversal
o Spanning Trees
o Minimum Spanning Trees
11.1 Introduction to Trees
3
o Introduction to Trees
o Rooted Trees
o Trees as Models
o Properties of Trees
4
Trees
Trees
5
Tree: It is a connected undirected graph with no simple circuits.
Example: Which of these graphs are trees?
Solution: G1 and G2 are trees - both are connected and have no cycles.
G3 is not a tree Because e, b, a, d, e is a cycle. G4 is not a tree because
it is not connected.
Trees
6
Forest: It is a graph that has no simple circuit but it is not connected.
Each of the connected components in a forest is a tree.
Theorem: An undirected graph is a tree if and only if there is a unique
simple path between any two of its vertices.
Rooted Trees
7
o Rooted tree: It is a tree in which one vertex has been designated
as the root and every edge is directed away from the root.
o Unrooted tree: It is converted into different rooted trees when
different vertices are chosen as the root.
Rooted Tree Terminology
8
o If v is a vertex of a rooted tree other than the root, the parent of v is the
unique vertex u such that there is a directed edge from u to v.
o When u is a parent of v, v is called a child of u.
o Vertices with the same parent are called siblings.
o The ancestors of a vertex are the vertices in the path from the root to this
vertex, excluding the vertex itself and including the root.
o The descendants of a vertex v are those vertices that have v as an
ancestor.
o A vertex of a rooted tree with no children is called a leaf.
o Vertices that have children are called internal vertices.
o If a is a vertex in a tree, the subtree with a as its root is the subgraph of
the tree consisting of a and its descendants and all edges incident to
these descendants.
Terminology for Rooted Trees
9
Example: In the rooted tree T (with root a):
1. Find the parent of c, the children of g, the siblings of h, the
ancestors of e, and the descendants of b.
2. Find all internal vertices and all leaves.
3. What is the subtree rooted at g?
Solution:
1. The parent of c is b.
The children of g are h, i, and j.
The siblings of h are i and j.
The ancestors of e are c, b, and a.
The descendants of b are c, d, and e.
2. The internal vertices are a, b, c, g, h, and j.
The leaves are d, e, f, i, k, l, and m.
3. We display the subtree rooted at g.
m-ary Rooted Trees
10
m-ary tree: A rooted tree is called an m-ary tree if every internal vertex has no more than m
children.
full m-ary tree: The tree is called a full m-ary tree if every internal vertex has exactly m
children. An m-ary tree with m = 2 is called a binary tree.
Example: Are the following rooted trees full m-ary trees for some positive integer m?
Solution: T1 is a full binary tree because each of its internal vertices has two children.
T2 is a full 3-ary tree because each of its internal vertices has three children.
T3 is a full 5-ary tree, because in T3 each internal vertex has five children.
T4 is not a full m-ary tree for any m because some of its internal vertices have two children and
others have three children.
Ordered Rooted Trees
11
o Ordered rooted tree: It is a rooted tree where the children of each internal
vertex are ordered. (from left to right).
o If an internal vertex of a binary tree has two children, the first is called the
left child and the second the right child.
o The tree rooted at the left child of a vertex is called the left subtree of this
vertex, and the tree rooted at the right child of a vertex is called the right
subtree of this vertex.
Example: Consider the binary tree T.
(i) What are the left and right children of d?
(ii) What are the left and right subtrees of c?
Solution:
(i) The left child of d is f and the right child is g.
(ii) The left and right subtrees of c are displayed in (b) and (c).
Properties of Trees
12
Theorem 2: A tree with 𝑛 vertices has 𝑛 − 1 edges.
Theorem 3: A full 𝑚-ary tree with 𝑖 internal vertices has 𝑛 = 𝑚𝑖 + 1 vertices.
Theorem 4: A full m-ary tree with
I. 𝑛 vertices has 𝑖 = (𝑛 − 1)/𝑚 internal vertices and leaves, 𝑙 = [(𝑚 − 1)𝑛 + 1]/𝑚
II. 𝑖 internal vertices has 𝑛 = 𝑚𝑖 + 1 vertices and 𝑙 = (𝑚 − 1)𝑖 + 1 leaves,
III. 𝑙 leaves has 𝑛 = (𝑚𝑙 − 1)/(𝑚 − 1) vertices and 𝑖 = (𝑙 − 1)/(𝑚 − 1) internal
vertices.
Level of vertices and height of trees
13
o The level of a vertex v in a rooted tree is the length of the unique path from
the root to this vertex.
o The height of a rooted tree is the maximum of the levels of the vertices.
Example:
1. Find the level of each vertex in the tree to the right.
2. What is the height of the tree?
Solution:
1. The root a is at level 0.
Vertices b, j, and k are at level 1.
Vertices c, e, f, and l are at level 2.
Vertices d, g, i, m, and n are at level 3.
Vertex h is at level 4.
2. The height is 4, since 4 is the largest level of any vertex.
Balanced m-Ary Trees
14
Balanced m-Ary Trees: A rooted m-ary tree of height h is called balanced
if all leaves are at levels h or h − 1.
Example: Which of the rooted trees shown below is balanced?
Solution: T1 and T3 are balanced, but T2 is not because it has leaves at
levels 2, 3, and 4.
15
11.4 Spanning Trees
11.4 Spanning Trees
16
Let G be a simple graph. A spanning tree of G is a subgraph of
G that is a tree containing every vertex of G.
Example: Find the spanning tree of
this simple graph:
Solution: The graph is connected, but is not a tree because it contains 3 cycles. Remove the
edge {a, e}, the edge {e, f} and then the edge {c, g}
Example: Find the spanning tree of
this simple graph:
17
18
11.5 Minimum Spanning Trees
11.5 Minimum Spanning Trees
19
Theorem: Every connected graph contains a spanning tree.
Minimum spanning tree (MST): A minimum spanning tree in a
connected weighted graph is a spanning tree that has the smallest
possible sum of weights of its edges.
20
21
22
Minimum Spanning Trees (MST) (Cont…)
23
Find minimum spanning tree (T) of a connected graph G with
n vertices:
There are two algorithms: (notice that T must have n-1 edges.)
Algorithm 1:
1. Arrange the edges in the order of decreasing weights.
2. Proceed sequentially, delete each edge that does not disconnect
the graph until n - 1 edges remain.
Algorithm 2:
1. Arrange edges in order of increasing weights.
2. Start with vertices only and proceed sequentially, add each
edge which does not result in a cycle until n -1 edges are added.
Tree Graph; Spanning Trees; Minimum Spanning Trees (Cont…)
24
Example: Find the MST of this simple graph:
The weight of a MST is unique, but the MST itself is not.
Different MST can occur when two or more edges have the same
weight.