Module 5
Module 5
MODULE-5
TREES
Not a tree as it
contain cycle
Not connected so not tree,
but each component is a
tree and collectively called
(a)
forest.
(b)
11-04-2023 Discrete Mathematics & Grapg Theory 2
Theorems
2. If in a graph G there is one and only one path between every pair of vertices then G is a tree
Note: A disconnected graph with n vertices and n-1 edges need not be a tree
Note:
(a) The complete graph Kn is not a tree when n > 2.
(N × 1) + (2 × 2) + (4 × 3) + (3 × 4) = 2(N + 8)
N + 4 + 12 + 12 = 2N + 16
2N – N = 28 – 16 , Therefor N = 12.
11-04-2023 Discrete Mathematics & Grapg Theory 5
Rooted Trees
In a rooted tree we denote a root by ‘r’ and draw the tree down wards from upper level to lower level
so that arrows can be dropped, then the root will be at the uppermost level and all other vertices will
be at the lower level.
(b)
(a)
11-04-2023 Discrete Mathematics & Grapg Theory 6
Internal vertices
Binary Tree
• A rooted tree T is said to be binary tree if the out-degree of internal vertices of T is less than or equal to 2.
Balanced Tree
• A rooted tree T of height h is said to be balanced tree if the level number of the leaf is h or h-1.
Complete Binary Tree
• A rooted tree T is said to be complete binary tree if the out-degree of internal vertices of T is equal to 2.
11-04-2023 Discrete Mathematics & Grapg Theory 8
Full binary Tree
Note:
Let T be a complete m-ary tree of order n with p leaves and q internal vertices then we have
𝑚𝑝−1
a) 𝑛 = 𝑚𝑞 + 1 =
𝑚−1
𝑚−1 𝑛+1
b) 𝑝 = 𝑚 − 1 𝑞 + 1 =
𝑚
𝑛−1 𝑝−1
c) 𝑞 = =
𝑚 𝑚−1
11-04-2023 Discrete Mathematics & Grapg Theory 9
Examples
𝑞=9
Therefore the number of cords required are = 9 – 1 = 8.
▪ Suppose we wish to sort (rearrange/reorganise) a given list of n integers in non decreasing order.
▪ The most common (and the easiest) way of carrying out this sorting consists of two parts.
▪ In the first part, we recursively split the given list and all subsequent lists in half (or as close as
▪ In the second part, we merge the sublists in increasing order until the original n integers have been
sorted.
▪ The splitting and merging process is done by the use of balanced complete tree.
{12, 11, 2, 3, 1, 5} {6, 7, 10, 9, 4, 15} {11, 12} {2} {1, 3} {5} {6, 7} {10} {4, 9} {15}
{12, 11, 2} {3, 1, 5} {6, 7, 10} {9, 4, 15} {2, 11, 12} {1, 3, 5} {6, 7, 10} {4, 9, 15}
{12, 11} {2} {3, 1} {5} {6, 7} {10} {9, 4} {15} {1, 2, 3, 5, 11, 12} {4, 6, 7, 9, 10, 15}
{12} {11} {3} {1} {6} {7} {9} {4} {1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 15}
Solution:
{-1, 0} {2} {-2} {3} {6, -3} {5} {1} {4}
{-1, 0, 2, -2, 3, 6, -3, 5, 1, 4} {-1} {0} {-2} {3} {6} {-3} {1} {4}
{-1, 0, 2, -2, 3} {6, -3, 5, 1, 4} {-1, 0} {2} {-2, 3} {-3, 6} {5} {1, 4}
{-1, 0} {2} {-2} {3} {6, -3} {5} {1} {4} {-2, -1, 0, 2, 3} {-3, 1, 4, 5, 6}
{-1} {0} {-2} {3} {6} {-3} {1} {4} {-3, -2, -1, 0, 1, 2, 3, 4, 5, 6}
• Binary sequences are used as codes of message transmitting. For a message consisting the letters a, e, n, r, t
is to be transmitted. Then coding scheme:
a : 1, e : 0, n : 10, r : 01, t = 101
• Suppose with the above code, the message ‘eat’ should be transmitted. Then the code will be 01101. which
is wrong, as it also reads as rt, rar, or eaar.
• If the following code is used a : 10, e : 0, n : 1101, r : 111, t = 1100, then the message ‘eat’ is transmitted to
sequence 0101100. Which is correct.
6 7 8
= 6 + 12 + 12 + 14 + 16
2 4
= 60
We note that the vertices A and B carry the smallest weights, 4 and 5. Add these weights to get the weight 9 and assign it
to a new vertex vj. Draw a tree having v1 as the root and A and B as its children. Rearrange the vertices present at this
stage (namely the new vertex v1 and the old vertices C, D, E, F) in the non-decreasing order of their weights. The resulting
graph is shown in Figure (ii).
11-04-2023 Discrete Mathematics & Grapg Theory 19
@ Dr Vishal Patil, FET Jain (Deemed-to-be University)
Now, among the vertices C, v1, D, E, F, two vertices which carry the smallest weights are C and v₁. Add their weights (8 and
9) to get a new weight 17. Assign this weight to a new vertex v2 and draw a tree having v2 as the root and C and v1 as its
children. Rearrange the vertices present at this stage (namely v2, D, E, F) in the non-decreasing order of their weights. The
resulting graph is shown below.
Among the vertices D, E, v2, F, the two vertices which carry minimum weights are D and E. Add their weights (15 and 16) to
get a new weight 31. Assign this weight to a new vertex v3 and draw a tree having v3 as the root and D and E as its children.
Rearrange the vertices present at this stage (namely v2, v3 and F) in the non-decreasing order of their weights. The
resulting graph is shown below.
11-04-2023 Discrete Mathematics & Grapg Theory 20
@ Dr Vishal Patil, FET Jain (Deemed-to-be University)
Among the vertices v2, F, v3, the two vertices which carry smallest weights are v2 and F. Add their weights (17 and 25) and
get a new weight 42. Assign this weight to a new vertex V4 and draw a tree having v4 as the root and v2 and F as its children.
Rearrange the vertices v3 and v4 in the non-decreasing order of their weights. The resulting graph is shown below
The disconnected graph shown above consists of two trees having v3 and v4 as roots. Add their weights (31 and 42) and get
a new weight 73. Assign this weight to a new vertex r and draw a tree having r as the root and v3 and v4 as its children. Thi s
tree is shown in Figure (vi).
11-04-2023 Discrete Mathematics & Grapg Theory 21
@ Dr Vishal Patil, FET Jain (Deemed-to-be University)
The tree obtained as explained above (that is the tree shown in Figure (vi)) is a complete, weighted binary tree whose
leaves are the vertices A, B, C, D, E, F with which we started. This tree serves as an optimal tree for the weights considered.
Keeping the weights of A, B, C, D, E, F in mind and noting their levels in the above tree, we find that the weight of the
optimal tree is
W(T) = (4×4)+(5x4) + (8 x 3) + (15 x 2) + (16 x 2) + (25 x 2) = 172
The procedure adopted in constructing an optimal tree as illustrated above is known as Huffman's procedure. The tree
itself is often called an Huffman's tree. This tree is not unique
The leaves of the above tree and the binary sequences that identify these leaves are shown
in the following Table:
Leaf: A B C D E F
Binary sequence: 1010 1011 100 00 01 11
This Table displays an optimal prefix code for the symbols A, B, C, D, E, F. Since the optimal
tree is not unique, the optimal prefix code is also not unique.
Solution: Treating the given frequencies as the weights and the corresponding symbols as the isolated vertices, we first
arrange the symbols such that their frequencies are in nondecreasing order. This is shown below:
Now, we construct an optimal tree having q, z, y, u, a, o as leaves by using the Huffman's procedure. The construction is
done step-by-step and the graphs obtained in these steps are shown below in the order of their occurrence. (See Figures
(ii)-(vi)). The final graph is labelled (using the labelling procedure) and depicted in Figure 3.49.
We now construct an optimal tree having these symbols as leaves by using the Huffman procedure. The graphs obtained in
successive steps of the procedure are shown below in Figures (ii)-(viii) in the order of their occurrence. The labelled version
of the final trees hown in Figure (viii)
• Every connected graph has a spanning tree, any two spanning trees have the same number of edges.
• A weighted graph is a graph in which each edge has an associated real number weight.
• A minimal spanning tree (MST) is a spanning tree with the least total weight of its edges.
Theorems
G, then the edges of G which are not in T are called the chords of G with respect to T. The set of all chords of G
ഥ. Evidently
is the complement of T in G. This set is called the chord-set or cotree of T in G and is denoted by 𝑻
n1 n1 n1
ഥ.
G= TU𝑻
n2 n3 n2 n3 n2 n3
n4 n5 n4 n5 n4 n5
(a) : G (b) : T ഥ
(c) : 𝐓
Note:-The Graph G = (V, E) is an undirected graph then G is connected if and only if G has a spanning tree.
11-04-2023 Discrete Mathematics & Grapg Theory 30
@ Dr Vishal Patil, FET Jain (Deemed-to-be University)
1. Find the spanning trees of the graph. 2. Find the spanning trees of the graph. Find all the non-
isomorphic spanning trees of the graph G.
Solution
Solution
Kruskal Algorithm:
The working rule for the Kruskal’s method (usually called Kruskal’s algorithm) may be stated as follows
➢ Step1: Given a connected, weighted graph G with n vertices, list the edges of G in the order of nondecreasing weights.
➢ Step2: Starting with a smallest weighted edge, proceed sequentially by selecting one edge at a time such that no cycle is
formed.
➢ Step3: Stop the process of step2 when (n-1) edges are selected. These (n-1) edges constitute a minimal spanning tree of G.
Remarks
➢ If two or more edges have the same weight, there will be more than one listing of edges in non-decreasing order of
weights. Different listing may yield different minimal spanning trees. As such, Kruskal algorithm does not determine a
unique minimal spanning tree.
➢ The process in step2 is called Greedy Process.
11-04-2023 Discrete Mathematics & Grapg Theory 33
Example
Using Kruskal’s Algorithm, find a minimal spanning tree for the given weighted graph
Thus, a minimal spanning tree of the given graph contains the five edges CR, PR,
QR, BQ, AB. This tree is shown in the figure. The weight of the tree is 37 units.
11-04-2023 Discrete Mathematics & Grapg Theory 34
Example
Using Kruskal’s Algorithm, find a minimal spanning tree for the given weighted graph
Solution
We observe that the graph has 5 vertices. Therefore the minimal spanning tree there of will have 4 edges. Let us tabulate the
weights of the edges between every pair of vertices as shown below
v1 v2 v3 v4 v5
v1 - 4 ∞ ∞ 5
v2 4 - 3 6 1
v3 ∞ 3 - 6 2
v4 ∞ 6 6 - 7
v5 5 1 2 7 -
Now let us start with the first row (v1 row) and pick the smallest entry therein. This is 4 which corresponds to the edge
{v1, v2}. By examining all the entries in v1- and v2-rows, we find that the vertex other than v1 and v2 which corresponds
to smallest entry is v5 (smallest entry being 1). Thus v5 is closest to the edge {v1, v2}. Let us connect v5 to the {v1, v2} at
v2 (because {v5, v2} has smaller weight than {v5, v1}).
11-04-2023 Discrete Mathematics & Grapg Theory 37
@ Dr Vishal Patil, FET Jain (Deemed-to-be University)
Let us now examine the v5-row and note that small entry is 1 which corresponds to the edge {v5, v2}. By examining all
entries in v2- and v5 rows, we find that the vertex other than v2 and v5 which corresponds to the smallest entry v3. thus v3
is closest to the edge {v2, v5}.
Thus the edges {v1, v2}, {v2, v5}, {v5, v3} belongs to a minimal spanning tree. The vertices left over at this stage is v4
which is joined to v2, v3, and v5 in the given graph. Among the edges that contain v4, the edges {v2, v4} and {v3, v4}
have equal minimal weights. Therefore we can include either of those edges in the minimal spanning tree.
Accordingly, the degree {v1, v2}, {v2, v5}, {v5, v3} together with the edge {v2, v4} or the edge {v3, v4} constitute a
minimal spanning tree. Thus, for the given graph, there are two minimal spanning trees as shown in the figure (a), (b). The
weight of each of these trees is 13 units.
Solution
We observe that the graph has 6 vertices. Therefore the minimal spanning tree thereof will have 5 edges. Let us tabulate the
weights of the edges between every pair of vertices as shown below
A B C D E F
A - 2 4 ∞ ∞ 2
B 2 - 1 ∞ 4 ∞
C 4 1 - 3 3 1
D ∞ ∞ 3 - 3 5
E ∞ 4 3 3 - 4
F 2 ∞ 1 5 4 -