0% found this document useful (0 votes)
114 views107 pages

Dms Module 5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views107 pages

Dms Module 5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

Graph: A graph is a pair (V, E) where V is a non-empty set and E is a set

of unordered pairs of elements taken from the set V.


 For a graph (V, E) the elements of V are called vertices or points or
nodes and the elements of E are called edges or undirected edges. The
set V is called the vertex set and the set E is called the edge set.
 The graph (V, E) is also denoted by G = (V, E) or G = G (V, E) or G.
Null graph: A graph containing no edge is called a null graph.

Ex:
Here V = {a, b, c} and E = { }
Trivial graph: A null graph with only one vertex is called a trivial graph.
Ex:
Here V = {a} and E = { }
Finite graph: A graph with only a finite number of vertices and edges
is called a finite graph otherwise it is called an infinite graph.
Available At VTU HUB (Android App)
Order and Size: The number of vertices in a graph is called the order of the
graph and the number of edges in it is called its size.
In other words, for a graph G = (V, E) the cardinality of the set V denoted by
|V|, is called the order of G and the cardinality of the set E denoted by |E|, is
called the size of G. A graph of order n and size m is called a (n, m) graph.

End Vertices: If vi and vj denote two vertices of a graph and if ek denotes the
edge joining vi and vj, then vi and vj are called the end vertices of ek .
Ex:
Here a and b are the end vertices of e1.

Loop: An edge whose end vertices are one and the same is known as a loop.
Ex:

Parallel edges: Two edges which have the same end vertices are known as
parallel edges. Ex:
Available At VTU HUB (Android App)
Multiple edges: If in a graph, there are two or more edges with the same end
vertices, the edges are called multiple edges.

Ex:

Simple graph: A graph which does not contain loops and multiple edges is
called a simple graph. Ex:

Multi graph: A graph which contains multiple edges but no loops is called a
multi graph.
Ex:

General graph: A graph which contains multiple edges and / or loops is


called a general graph. Ex:

Available At VTU HUB (Android App)


Incidence: When a vertex v of a graph G is an end vertex of an edge e in a
graph G, then the edge e is incident on or to the vertex v.
 Since every edge has two end vertices, every edge is incident on two
vertices, one at each end.
 The two end vertices are co-incident if the edge is a loop.

Adjacent vertices: Two vertices are said to be adjacent vertices or


neighbors if there is an edge joining them.

Adjacent edges: Two non-parallel edges are said to be adjacent edges if


they are incident on a common vertex i.e, if they have a vertex in common.

Ex:

In the above graph, A and B are adjacent vertices and e1, e2 are adjacent
edges.
Available At VTU HUB (Android App)
Complete graph: A simple graph of order >= 2 in which there is an edge
between every pair of vertices is called a complete graph or a full graph. It
is denoted by Kn .
 Complete graph with two, three, four and five vertices are shown in
figures below:

 A Complete graph with five vertices is known as Kurtowiski’s first graph.


Bipartite graph: Suppose a simple graph G is such that its vertex set V is
the union of its mutually disjoint nonempty subsets V1 and V2 which are such
that each edge in G joins a vertex in V1 and a vertex in V2. Then G is called a
bipartite graph.
 If E is the edge set of this graph, the graph is denoted by G = (V1, V2, E)
or G = G (V1, V2, E). The sets V1 and V2 are called bipartites or partitions
of the vertex set V.
Available At VTU HUB (Android App)
For example, consider the graph G shown below for which the vertex set
V = {A, B, C, P, Q, R, S} and the edge set E = {AP, AQ, AR, BR, CS, CQ}.

 Note that V is the union of the subsets V1 = {A, B, C}, V2 = {P, Q, R, S}


which are such that V1, V2 are disjoint, every edge in G joins a vertex in
V1 to a vertex in V2.

 G contains no edge that joins two vertices both of which are in V1 or V2.
This graph is a bipartite graph with V1 = {A, B, C}, V2 = {P, Q, R, S} as
bipartites.

Available At VTU HUB (Android App)


Complete Bipartite graph: A bipartite graph G = G (V1, V2, E) is called a
complete bipartite graph if there is an edge between every vertex in V1 and
every vertex in V2 .
The following figures show some complete bipartite graphs:

 Complete bipartite graph G = G (V1, V2, E) in which the bipartites V1, V2


contains r, s vertices respectively with r <= s is denoted by Kr, s.

 In this graph, each of r vertices in V1 is joined to each of s vertices in V2.


Thus Kr, s contains r+s vertices and rs edges i.e., the order is r+s and
size is rs. Therefore Kr, s is a (r+s, rs) graph.

 The graph K3, 3 is known as Kuratowski’s second graph.

Available At VTU HUB (Android App)


Problems:
Q1: If G = G(V, E) is a simple graph, prove that 2 E  V 2  V
Solution: In a simple graph, there are no multiple edges.
Each edge of a graph is determined by a pair of vertices, i.e., for a pair of
vertices, we can have only one edge (2 vertices  1 edge) .
Hence for a simple graph with n >= 2, number of edges cannot exceed
number of pair of vertices.
i.e., m  nC2  number of pair of vertices that can be chosen from
((
n vertices is nC2 )
n!
m
(n  2) ! 2 !

n (n  1) ( n  2) ! n (n  1)
m  m
(n  2) ! 2 2

 2m  n 2  n
2
 2 E  V V
Available At VTU HUB (Android App)
Q2: Show that a complete graph with n vertices, namely Kn has
1
n (n  1) edges.
2

Solution: In a complete graph, there exists exactly one edge between every
pair of vertices.
Therefore,
the number of edges in a complete graph = the number of pair of vertices.

i.e., m  nC2  number of pair of vertices that can be chosen from


((
n vertices is nC2 )
n!
 m
( n  2) ! 2 !

n (n  1) (n  2) !
 m
( n  2) ! 2

n (n  1)
 m
2
1
Thus, in a complete graph with n vertices, no. of edges = m  n (n  1) .
Available At VTU HUB (Android App)
2
Q3: Show that a simple graph of order 4 and size 7 and a complete
graph of order 4 and size 5 do not exist.
Solution:
(i) By data, order n = 4, size = m = 7
For a simple graph, 2m  n 2  n

 2  7  42  4

 14  12 ( which is false)
Thus, a simple graph of order 4 and size 7 does not exist.
(ii) By data, order n = 4, size = m = 5
1
For a complete graph, m  n (n  1)
2
1
 5  4 ( 4  1)
2
 5  6 ( which is false)

Thus, a complete graph of order 4 and size 5 does not exist.


Available At VTU HUB (Android App)
Q4: (i) How many vertices and how many edges are there in the
complete bipartite graphs K4, 7 and K7, 11 ?
(ii) If the graph Kr, 12 has 72 edges, then what is r ?
Solution:
A complete bipartite graph Kr, s has r+s vertices and rs edges.

(i) The graph K4, 7 has 4+7 = 11 vertices and 4*7 = 28 edges
and the graph K7, 11 has 7+11 = 18 vertices and 7*11 = 77 edges.

(ii) Given that the graph Kr, 12 has 72 edges.

Consider m = rs
72 = r*12
This gives r = 6.

Available At VTU HUB (Android App)


Q5: Let G = (V, E) be a simple graph of order ‘n’ and size ‘m’. If G is a
bipartite graph, then prove that 4m  n 2
Solution: Let V1 and V2 be bipartites of G, with V1  r and V2  s
Since for the given graph, V  n
We must have r + s = n , so that s = n – r .
The graph G has the maximum number of edges when each of the ‘r’
vertices in V1 is joined by an edge to each of the ‘s’ vertices in V2 and this
maximum is equal to r  s
 m  rs      (1)
Consider r  s  r  ( n  r )
 r  s  nr  r 2
 r  s   ( r 2  nr )
Now let us complete the square and rewrite the term  (r 2  nr )
2 2
 n n 
Consider r  s    r      
 2   2  
Available At VTU HUB (Android App)
So that we get,
2 2
n  n
r s    r  
2  2
n
This is maximum when r 
2
n n2
Thus when r  , we get r  s 
2 4

Substituting this in RHS of equation (1), we get


n2
m
4
 4m  n 2

Thus if G is a bipartite graph, then 4m  n 2


where V  n , E  m .
Available At VTU HUB (Android App)
Q6: Show that a simple graph of order n = 4 and size m = 5 cannot be
a bipartite graph.

Solution:
For a bipartite graph, we have 4m  n 2    (1)

where order  V  n and size  E  m .

Given V  n  4 and E  m  5

Substituting in equation (1), we get

4  5  42
i.e., 20  16 which is false .
Thus a simple graph of order n = 4 and size m = 5 cannot be a
bipartite graph.

Available At VTU HUB (Android App)


PrACtiCe Questions:

 Company X has offices in cities B, D and K; Company Y in cities B


and M; Company Z in cities C and M. Represent this situation by a
bipartite graph. Is this a complete bipartite graph?

 State whether the following graphs can exist or cannot exist:


(i) Simple graph of order 3 and size 2
(ii) Simple graph of order 5 and size 12
(iii) Complete graph of order 5 and size 10
(iv) Bipartite graph of order 4 and size 3
(v) Bipartite graph of order 3 and size 4
(vi) Complete bipartite graph of order 4 and size 4.

Available At VTU HUB (Android App)


remember:
 For a simple graph, 2m  n 2  n

1
 For a complete graph, m  n (n  1)
2

 For a bipartite graph, 4m  n 2

 For a complete bipartite graph Kr, s , there are r + s vertices and r*s
edges.

Available At VTU HUB (Android App)


Vertex Degree: Let G = G (V, E) be a graph and v be a vertex of G. Then
the number of edges of G that are incident on v with the loops counted
twice is called the degree of the vertex v and is denoted by deg (v) or d(v).
 The degrees of the vertices of a graph arranged in non – descending
order is called the degree sequence of the graph.
 The minimum of the degrees of vertices of a graph is called the degree
of the graph.

Ex: d (v1 )  3 , d (v2 )  4 , d (v3 )  4 , d (v4 )  3

Therefore the degree sequence of the graph is 3, 3, 4, 4 and the degree of


the graph is 3.
Isolated Vertex, Pendant Vertex & Pendant Edge:
A vertex is an isolated vertex if and only if its degree is zero.
A vertex of degree 1 is called a pendant vertex.
An edge incident on a pendent vertex is called a pendant edge.
Available At VTU HUB (Android App)
Regular Graph: A graph in which all the vertices are of the same degree k
is called a regular graph of degree k or k – regular graph.

Ex:

The graphs shown in figure (a), (b) are 2 – regular, 4 – regular graphs
respectively. A 3 – regular graph is called a cubic graph. The graph shown in
figure (c) is a 3 – regular (cubic) graph. This particular cubic graph has 10
vertices and 15 edges, which is called the PETERSEN graph. The graph
shown in fig (d) is a cubic graph with 8 = 23 vertices. This particular graph is
called 3D hypercube and is denoted by Q3.

In general, for any positive integer k, a loop free k – regular graph with 2k
vertices is called the k – dimensional hypercube (or k – cube) and is
denoted by Qk .
Available At VTU HUB (Android App)
Hand Shaking Property: The sum of the degrees of all vertices in a graph
is an even number and this number is equal to twice the number of edges
in the graph. i.e, for a graph G = (V, E),  deg(v)  2 E
vV

Proof: The above property is obvious from the fact that while counting the
degrees of vertices, each edge is counted twice(once at each end).

 This property is called the hand shaking property because it states that if
several people shake hands, then the total number of handshakes must be
even.

Theorem: In every graph, the number of vertices of odd degree is even.


Proof:
Consider a graph with ‘n’ vertices.
Suppose ‘k’ of these vertices are of odd degree, then the remaining n – k
vertices are of even degree.
Let us assume the ‘n’ vertices of the form: v1, v2, v3 ….vk, vk+1, vk+2…..vn .
Available At VTU HUB (Android App)
Let v1, v2, v3 ….vk be the vertices of odd degree ----- (*)
and vk+1, vk+2…..vn be the vertices of even degree.
n k n
Then  deg(v )   deg(v )   deg(v )
i 1
i
i 1
i
i  k 1
i     (1)

In view of Hand Shaking Property(HSP), the sum on the LHS of equation (1)
is equal to twice the number of edges in the graph. And this sum is even.
The second term(sum) in the RHS of equation (1), is the sum of the degree
of vertices with even degree each. So, this sum is also even.
Thus the first term(sum) in the RHS of equation (1) must also be even.
i.e., deg(v1 )  deg(v2 )  deg(v3 )  .....  deg(vk )  EVEN     (2)
But from the assumption made(*), each of deg(v1), deg(v2),.....deg(vk) is odd.
Therefore, number of terms in the LHS of equation (2) must be even.
i.e., k is even.
(Since odd numbers added even number of times, the result is even)
Hence the proof. Available At VTU HUB (Android App)
Problems:
Q1: Can there be a graph with 12 vertices such that two of the vertices
have degree 3 each and the remaining 10 vertices have degree 4 each? If
so, find its size.
Solution:
Sum of the degree of the vertices  (2  3)  (10  4)
= 46 , which is even.
Hence there can be a graph of the desired type.

To find the size of such graph,

By HSP, Sum of the degree of the vertices = twice the number of edges
i.e., 46  2 E

 E  23
Therefore , the size of such graph is 23.

Available At VTU HUB (Android App)


Q2: In a graph G = (V, E), what is the largest possible value for V
if E  19 and deg(v)  4 for all v  V ?
Solution:
Given: All the vertices are of degree > = 4
Therefore, Sum of the degrees of vertices > = 4n

 2 E  4n (since by HSP, Sum of the degree of the vertices


= Twice the number of edges)
 2 19  4n

 38  4n
38
 n  9.5  10
4
i.e., n  V  10

Thus the largest possible value of n = 9.


i.e., the given graph can have at most 9 vertices.
Available At VTU HUB (Android App)
Q3: Show that there is no graph with 12 vertices and 28 edges in the
following cases:
(i) The degree of a vertex is either 3 or 4.
(ii) The degree of a vertex is either 3 or 6.
Solution: Suppose there is a graph with 28 edges and 12 vertices, of which
k vertices are of degree 3 (each).
(i) If all the remaining (12 – k) vertices have degree 4, then by HSP,
3k  4(12 – k )  2  28
 3k  48 – 4k  56
 k 8  k  8 ( # which is not possible)
(ii) If all the remaining (12 – k) vertices have degree 6, then by HSP,
3k  6(12 – k )  2  28
 3k  72 – 6k  56
16
  3k  16  k ( # which is not possible)
3
Thus, the graphs of the desired types cannot exist.
Available At VTU HUB (Android App)
Q4: Show that there exists no simple graphs corresponding to the
following degree sequences:
(i) 0, 2, 2, 3, 4 (ii) 1, 1, 2, 3 (iii) 2, 3, 3, 4, 5, 6 (iv) 2, 2, 4, 6
Solution: (i) By HSP,  deg(v)  Even number
vV

 0  2  2  3  4  11  Even number
Thus no simple graph of degree sequence 0, 2, 2, 3, 4 exists.
(ii) By HSP, 1  1  2  3  7  Even number
Thus no simple graph of degree sequence 1, 1, 2, 3 exists.
(iii) By HSP, 2  3  3  4  5  6  23  Even number
Thus no simple graph of degree sequence 2, 3, 3, 4, 5, 6 exists.
(iii) By HSP, 2  2  4  6  14  Even number
But such a graph do not exist because with 4 vertices, we cannot draw a
simple graph having degrees 4 and 6.
Available At VTU HUB (Android App)
Q5: (i) If a graph with ‘n’ vertices and ‘m’ edges is k – regular, show
kn
that m 
2
(ii) Does there exist a cubic graph with 15 vertices?
(iii) Does there exist a 4-regular graph with 15 edges?
Solution:
(i) Given that the graph G is k – regular.
 the degree of every vertex is k.
Therefore, If G has n vertices, then the sum of the degree of vertices is nk.
By HSP, this must be equal to 2m (if G has m edges)
kn
i.e., nk  2m  m
2
(ii) If there is a cubic graph(3-regular graph) with 15 vertices, then the
kn
number of edges it should have is m 
2
3  15 45 (# since it is not an integer )
 m 
2 2
Thus a cubic graph with 15 vertices does not exist.
Available At VTU HUB (Android App)
(iii) If there is a 4 – regular graph with 15 edges (i.e., k = 4, m = 15), then
the number of vertices it should have is
2 m  kn 
n  sin ce m  
k  2

2  15 30 (# since it is not an integer )


n 
4 4
Thus a 4 - regular graph with 15 edges does not exist.

Available At VTU HUB (Android App)


Q6: Determine the order of the graph G = (V, E) in the following cases:
(i) G is a cubic graph with 9 edges.
(ii) G is regular with 15 edges.
(iii) G has 10 edges with 2 vertices of degree 4 and all others of degree 3.
Solution:
(i) Suppose the order of G is ‘n’.
Since G is a cubic graph, all vertices of G have degree 3.
Therefore, Sum of the degrees of the vertices = 3n.
By HSP,  deg(v)  2 E
vV

 3n  2  9 (Since G has 9 edges)

 n6
(ii) Given G is a regular graph, then all vertices of G must be of same
degree, say k.
Suppose the order of G is ‘n’.
Then, Sum of the degrees of the vertices = nk .
Available At VTU HUB (Android App)
By HSP,  deg(v)  2 E
vV

 nk  215 (Since G has 15 edges)


30
 n
k
Since ‘k’ is a positive integer, it follows that ‘n’ must be a divisor of 30.
i.e., n = 1, 2, 3, 5, 6, 10, 15, 30 (possible orders of G)

(iii) Suppose the order of G is ‘n’.


Given that, 2 vertices of G are of degree 4 and the remaining (n - 2) vertices
are of degree 3.
Then by HSP,  deg(v)  2 E
vV

 (2  4)  (n  2)  3  2 10 (Since G has 10 edges)

 3n  6  12

 3 n  18  n6
Available At VTU HUB (Android App)
2m
Q7: For a graph with ‘n’ vertices and ‘m’ edges, show that   
n
where  is the minimum and  is the maximum of the degree of the vertices.
Solution: Let d1, d2, d3,…..dn be the degrees of 1st, 2nd, …… nth vertex
respectively, then by HSP

 deg(v)  2 E
vV

 d1  d 2  d 3  .....  d n  2m     (1)

Given that  is the minimum of d1 , d 2 , d 3 ,....d n


i.e.,   d1 ,   d 2 ,   d 3 ,......   d n

       ......    d1  d 2  d 3  .......  d n (here  is added n times)

 n  2 m (from equation 1)
2m
        ( 2)
n
Available At VTU HUB (Android App)
It is also given that  is the maximum of d1 , d 2 , d 3 ,....d n

i.e.,   d1 ,   d 2 ,   d 3 ,......   d n

       ......    d1  d 2  d 3  .......  d n (here  is added n times)

 n 2m (from equation 1)

2m
 
n
2m
i.e.,        (3)
n
Thus combining equations (2) and (3), we get
2m
  
n

Available At VTU HUB (Android App)


PRACtiCe Questions:

 Consider a graph having ‘n’ vertices and ‘m’ edges. If ‘p’ number of
vertices are of degree k and the remaining vertices are of degree
k+1, then prove that p = (k+1)n – 2m.

 Prove that there is no simple graph with 7 vertices, one of which has
degree 2, 2 have degree 3, 3 have degree 4 and the remaining vertex
has degree 5.

Available At VTU HUB (Android App)


Isomorphism:
Two graphs G and G are said to be isomorphic to each other if there is a
one to one correspondence between their vertices and between their edges
such that the adjacency of vertices is preserved. The adjacency of vertices
preserved means that for any two vertices u and v in G, if u and v are
adjacent in G then the corresponding vertices u , v in G are also adjacent
in G , then we write G  G .

From the definition of the isomorphism of the graphs, it follows that if two
graphs are isomorphic, then they must have
(1) The same number of vertices
(2) The same number of edges
(3) An equal number of vertices with a given degree.
These conditions are necessary but not sufficient.
Available At VTU HUB (Android App)
This means that two graphs for which these conditions hold need not be
isomorphic. In particular two graphs of the same order and same degree need
not be isomorphic.

Available At VTU HUB (Android App)


Problems:
Q1: Verify that the 2 graphs given below are isomorphic:

Solution: Let us rewrite the given graphs and name them as G1 and G2.
Also we shall name the vertices of the 2 graphs.

u1 u2 v1 v4

u3 u4 v3 v2
G1 G2

The 2 graphs G1 and G2 has 4 vertices and 4 edges each.


And the degree of all the vertices in G1 and G2 are equal to 2.
Available At VTU HUB (Android App)
We observe that
u1  v1 u 2  v2 u3  v3 u 4  v4

This implies that, there is a 1 – 1 correspondence between the vertices of


G1 and G2.
Also
{u1 , u 2 }  {v1 , v2 } {u1 , u3}  {v1 , v3 }

{u2 , u 4 }  {v2 , v4 } {u3 , u4 }  {v3 , v4 }

This implies that, there is a 1 – 1 correspondence between the edges of


G1 and G2.
Also adjacency of the vertices is preserved.

Thus G1  G2

Available At VTU HUB (Android App)


Q2: Verify the 2 graphs given below are isomorphic:
A B A
P B
Q D P
S
C Q
R S
C
D
R
G1 G2
Solution: The 2 graphs G1 and G2 has 8 vertices and 12 edges each.
And the degree of all the vertices in G1 and G2 are equal to 3.
We observe that A  A , B  B , ......... R  R  , S  S .
This implies that, there is a 1 – 1 correspondence between the vertices of
G1 and G2.
Also {A , B}  {A , B}, {B , C}  {B , C}, ......... {R , S}  {R  , S}.
This implies that, there is a 1 – 1 correspondence between the edges of
G1 and G2.
Also adjacency of the vertices is preserved. Thus G1  G2
Available At VTU HUB (Android App)
Q3: By labeling the graphs show that following graphs are isomorphic:
u1 u2 v1 v5
u7 v4
u3 v2
u6 u4 v7 v6
u5 v3
G1 G2
Solution: The 2 graphs G1 and G2 has 7 vertices and 14 edges each.
And the degree of all the vertices in G1 and G2 are equal to 4 each.
We observe that ui  vi  i  1, 2 .... 7
{ui , u j }  {vi , v j }  i  1, 2, ... 7 and j  1, 2, .... 7
This implies that, there is a 1 – 1 correspondence between the vertices of
G1 & G2 and there is a 1 – 1 correspondence between the edges of G1 & G2.
Also adjacency of the vertices is preserved.
 G1  G2
Available At VTU HUB (Android App)
Q4: By labeling the graphs show that following graphs are isomorphic:
u1 v6

v10 v1 v7
u6
u10 u2 v2
u5 v5
u7
u9 v4 v3
u8
u4 u3 v9 v8
G1 G2
Solution: The 2 graphs G1 and G2 has 10 vertices and 15 edges each.
And the degree of all the vertices in G1 and G2 are equal to 3 each.
We observe that ui  vi  i  1, 2 ......10
{ui , u j }  {vi , v j }  i  1, 2, .....10 and j  1, 2, ....10
This implies that, there is a 1 – 1 correspondence between the vertices of
G1 & G2 and there is a 1 – 1 correspondence between the edges of G1 & G2.
Also adjacency of the vertices is preserved.
 G1  G2 Available At VTU HUB (Android App)
Q5: Determine whether the following graphs are isomorphic or not.
u1 (2) v1 (3)
u5 (2) v5 (3)
u6 (3)
u 4 (3) u8 (3) u 2 (3) v4 (3) v8 (3) v 2 ( 2)
v6 (2)

u 7 ( 2) v7 (2)

G1 G2
u3 (2) v3 (2)
Solution:
(Let us write the degrees within brackets while naming the vertices)
The 2 graphs G1 and G2 has 8 vertices and 10 edges each.
We observe that, in G1, the vertex u1 of degree 2 is adjacent to vertices u2
and u4 whose degrees are 3 each.
Now suppose, the vertex u1 in G1 corresponds to v2 in G2(since both
are of same degree)
Then we observe that, in G2 , the vertex v2 of degree 2 is adjacent to vertex
v1 of degree 3 and vertex v3 of degree 2.
Available At VTU HUB (Android App)
This implies that, the adjacency of vertices is not preserved.

Hence G1 is NOT ISOMORPHIC to G2.

Available At VTU HUB (Android App)


Q6: Determine whether the following graphs are isomorphic or not.
u1 (3) u 2 ( 4) v1 (3) v 2 ( 4)

u 5 ( 4)
v5 (4) v6 (4)
u6 (3)

u8 (3)
v8 (3) v7 (3)
u7 (4)

v4 (3) v3 (4)
u 4 ( 4) u3 (3)
G1 G2
Solution:
(Let us write the degrees within brackets while naming the vertices)
The 2 graphs G1 and G2 has 8 vertices and 14 edges each.
We observe that, the vertex u1 of degree 3 in the graph G1 is adjacent to
vertices u2, u4, u5, all of which are of degrees 4 each.
Now suppose, the vertex u1 in G1 corresponds to v1 in G2(since both
are of same degree)
Then we observe that, in G2 , the vertex v1 is adjacent to v2, v4 and v5
whose degrees are 4, 3, Available
4 respectively.
At VTU HUB (Android App)
This implies that, the adjacency of vertices is not preserved.

Hence G1 is NOT ISOMORPHIC to G2.

Available At VTU HUB (Android App)


PRACtiCe Questions:
Verify the following graphs are Isomorphic or not?

1.

2.

Available At VTU HUB (Android App)


3.

4.

Available At VTU HUB (Android App)


Sub graphs:
Given two graphs G, G1 ,we say that G1 is a sub graph of G if the
following conditions are satisfied:
(i) All the vertices and edges of G1 are in G.
(ii) Each edge of G1 has the same end vertices in G as in G1.

Spanning Sub graph:


A sub graph G1 of a graph G is a spanning sub graph of G whenever the
vertex set of G1 contains all the vertices of G.
Thus, a graph and all its spanning sub graphs have the same vertex set.

Ex:

For the graph shown in fig (a), the graph in fig (b) is a spanning sub graph
whereas the graph in fig (c) is a sub graph, but not a spanning sub graph.
Available At VTU HUB (Android App)
Induced Sub graph:
Given a graph G = (V, E), if there is a sub graph G1 = (V1, E1) of G such that
every edge {A, B} of G is an edge of G1 also, where A, B  V1
Then G1 is called an induced sub graph of G (induced by V1) and is
denoted by V1

Ex:

For the graph shown in fig (a), the graph shown in fig (b) is an induced sub
graph, induced by the vertex set V1 = {v1, v2, v3, v4} whereas the graph
shown in fig (c) is not an induced sub graph since there is no edge between
v3 and v4.

Available At VTU HUB (Android App)


Edge disjoint and Vertex disjoint Sub graphs:
Let G be a graph and G1 and G2 be two sub graphs of G then,
(i) G1 and G2 are said to be edge disjoint if they do not have any common
edge. (ii) G1 and G2 are said to be vertex disjoint if they do not have any
common edge and any common vertex.

Ex 1:

G G1 G2
For the graph G, the graphs G1 and G2 are vertex disjoint, as well as
edge disjoint sub graphs.

Ex 2:

G G1 G2
The graphs G1 and G2 are edge disjoint, but not vertex disjoint since A
and D are common vertices inAtGVTU
Available 1 and G(Android
HUB 2. App)
oPerations on GraPhs
Consider two graphs G1 = (V1, E1) and G2 = (V2, E2). Then the graph whose
vertex set is V1  V2 and the edge set is E1  E 2 is called the union of G1 , G 2
and is denoted by G1  G2 .
Thus G1  G 2  V1  V2 , E1  E 2 
If V1  V2   then the graph whose vertex set is V1  V2 and the edge set is

E1  E 2 , is called the intersection of G1 , G2 and is denoted by G1  G2 .


Thus G1  G 2  V1  V2 , E1  E 2  if V1  V2  0
The graph whose vertex set is V1  V2 and the edge set is E1E 2 where E1E 2
is the symmetric difference of E1 , E2. (The symmetric difference E1E 2
denotes the set of all those elements (here edges) which are in E1 or E2 but
not in both) This graph is called the ring sum of G1, G2 and it is denoted by
G1G2 . Thus G1G 2  V1V2 , E1E 2 .

Available At VTU HUB (Android App)


For the graphs shown in figures below, their union, intersection and the ring
sum is shown:

Decomposition: A graph G is decomposed or partitioned into two sub


graphs G1, G2 if G1  G2  G and G1  G2    Null graph

Deletion: If v is a vertex in a graph G, then G – v denotes the graph


obtained by deleting v and all the edges incident on v, from G.
This graph G – v, is referred as vertex deleted sub graph of G.
Deletion of a vertex always results in the deletion of all the edges incident
on that vertex. G – v is a sub graph of G induced by
V1  V  {v}.
Available At VTU HUB (Android App)
If e is an edge in a graph G, then G – e denotes the sub graph of obtained by
deleting e (but not its end vertices) from G.
This sub graph is called edge – deleted sub graph of G.
The deletion of an edge does not alter the number of vertices. As such, an
edge deleted sub graph of a graph is a spanning sub graph of the graph.
For the graph G shown in fig (a), the sub graphs G – v and G – e are shown
in fig (b) and fig (c) respectively.

Available At VTU HUB (Android App)


Complement of a Simple graph: Complement of a simple graph G is
the graph obtained by deleting those edges which are in G and adding the
edges which are not in G, usually denoted by G .
Note: 1) G and G have the same vertex set.
2) Two vertices are adjacent in G iff they are not adjacent in G .
3) Complement of a complete graph Kn is a null graph.
4) G  K n  G .

Ex:

G K4 G
Self Complementary graphs: A simple graph G which is isomorphic to its
complement is called a self complementary graph.

Ex:  GG

G G
Available G (Android App)
At VTU HUB G
Problems:
Q1: Let G be a simple graph of order ‘n’. If the number of edges in G is
56 and in G is 80 , then what is the value of n ?
Solution:
We have G  K n  G

 number of edges in G  number of edges in K n  number of edges in G


1
 80  n(n  1)  56
2
 (56  80)  2  n 2  n
 n 2  n  272  0
Solving, we get n = 17 , n = - 16.
But, n is the number of vertices in the given simple graph G, which cannot
be negative.
Thus order of G = n =17.
Available At VTU HUB (Android App)
Q2: Find an example of a self complementary graph on 4 vertices and
one on 5 vertices.
Solution: We know that a simple graph G which is isomorphic to its
complement is called a self complementary graph.
Example on 4 vertices:

G G
Example on 5 vertices:

G G
Available At VTU HUB (Android App)
Tree: A graph G is said to be a tree if it is connected and has no cycles.
A graph which is tree is usually denoted by T.

Ex:

The graphs 1, 2, 3, shown above are all trees.

The graphs 4, 5 shown above are not trees since the 4th graph contains a
cycle, whereas the 5th one is not connected.

Leaf: A pendant vertex of a tree is called a leaf.


Forest: Group of trees form a forest. i.e., each component of a disconnected
graph is a tree. Such graphs form a forest.
Available At VTU HUB (Android App)
imPoRTAnT ThEoREm:
A tree with ‘n’ vertices has n – 1 edges.
(Or)
For a tree with ‘n’ vertices and ‘m’ edges, m = n – 1 i.e., E  V  1.
Proof:
Proof is by Induction on ‘n’.
Basic Step:
For n = 1, number of edges = m = 0 (true)

For n = 2, number of edges = m = 1 (true)

For n = 3, number of edges = m = 2 (true)

Thus basic step is satisfied.

Available At VTU HUB (Android App)


Induction Step:
Assume that the result is true for all trees with ‘n’ vertices where n  k .
Consider a tree T with k+1 vertices.
In T, let ‘e’ be an edge with end vertices ‘u’ and ‘v’.

Deletion of ‘e’ from T will disconnect the graph and T – e has exactly 2
components say T1 and T2.
Since T has no cycles, both T1 and T2 has no cycles.
This implies that T1 and T2 are trees.
Both T1 and T2 have less than k+1 vertices each (since T with k+1 vertices).
Therefore by assumption, theorem holds for T1 and T2 .
i.e., both T1 and T2 has one edge less than the number of vertices in it.

Available At VTU HUB (Android App)


Now, the total number of vertices in T1 and T2 (taken together) i.e., in T – e is
k+1 and the total number of edges in T1 and T2 (taken together) is
(k+1) – 2 = k – 1.

Therefore T – e has k – 1 edges.


 T has exactly k edges.
Hence a tree with k+1 vertices has k edges.

Thus by Induction, a tree with ‘n’ vertices has n – 1 edges.

Available At VTU HUB (Android App)


Problems:
Q1: Prove that a tree with 2 or more vertices contains at least 2 leaves
(pendant vertices).
Solution: Consider a tree T with ‘n’ vertices, where n >= 2.
Then it has n – 1 edges.
If d1, d2, d3, …… dn are the degrees of the vertices of T, then by HSP,

 deg(v)  2 E
vV

 d1  d 2  d 3  ......  d n  2(n  1)

 d1  d 2  d 3  ......  d n  2n  2      (1)

If each of d1, d2, d3, …… dn is > = 2 , then


d1  d 2  d 3  ......  d n  2n
 2n  2  2n ( using (1)) which is a contradiction.
Thus at least one of the d ’s is less than 2.
Available At VTU HUB (Android App)
Say d1 = 1 (d1  0 because T is connected  no ' d ' is zero)
Then
1  d 2  d 3  ......  d n  2n  2 (substituting d1 = 1 in equation (1))

 d 2  d 3  ......  d n  2n  2  1

 d 2  d 3  ......  d n  2n  3      (2)

Now, if each of d2, d3, …… dn is > = 2 , then

d 2  d 3  ......  d n  2( n  1)

 d 2  d 3  ......  d n  2n  2

 2 n  3  2n  2 ( using (2)) which is a contradiction.


Therefore there is at least 1 more ‘d ’ whose degree = 1.
Thus in T, there exists at least 2 vertices of degree 1.
i.e., there are at least 2 leaves (pendant vertices).
Available At VTU HUB (Android App)
Q2: Let F be a forest with ‘k’ components(trees). If ‘n’ is the number of
vertices and ‘m’ is the number of edges in ‘F’, then prove that n = m + k.
Solution:
Let H1, H2, H3, ……. Hk be the components of F.
Since each of these is a tree, if ni is the number of vertices in Hi and mi is
the number of edges in Hi , then
mi  ni  1 for i  1, 2, 3, ...... k
 m1  m2  m3  .........  mk  (n1  1)  (n2  1)  (n3  1)  .........  (nk  1)

 m  (n1  n2  n3  .......  nk )  (1  1  1  ......  1) ( k times )

 mnk

 nmk

Available At VTU HUB (Android App)


Q3: (i) Let T1 = (V1, E1) and T2 = (V2, E2) be 2 trees. If E1  15 and
V2  3 V1 , Determine V1 , V2 , E 2

Solution:
Consider V1  E1  1
 V1  15  1  16

Given V2  3 V1

 V2  3  16  48

Consider V2  E 2  1

 E 2  V2  1

 E 2  48  1  47

Available At VTU HUB (Android App)


Q4: If a tree has 400 vertices, then find the sum of the degree of the
vertices.
Solution:
Given V  400

 E  V  1  399

By HSP, Sum of the degrees of the vertices  2 E

 2  399

 798 .

Available At VTU HUB (Android App)


Q5: In a tree, if the degree of every non-pendant vertex is 3, then show
that the number of vertices in the tree is an even number.
Solution:
Let ‘n’ be the number of vertices in a tree T.
Then, the number of edges in the tree = (n – 1).
Let ‘k’ be the number of pendant vertices(i.e., vertices of degree 1).
Then, there are (n – k) non – pendant vertices.
Given that the degree of every non-pendant vertex is 3, then by HSP,

 deg v  2
vV
E

 (k 1)  (n  k )  3  2 (n  1)

 k  3n  3k  2n  2

 n  2k  2

 n  2(k  1) , which is an even number .


Available At VTU HUB (Android App)
Q6: Suppose that a tree T has N1 vertices of degree 1, N2 vertices of
degree 2, N3 vertices of degree 3, ……….. Nk vertices of degree k.
Prove that N1 = 2 + N3 + 2N4 + …….. + (k – 2)Nk.
Solution:
Total number of vertices = N1 + N2 + N3 + ………. + Nk
And total number of edges = (N1 + N2 + N3 + ………. + Nk) – 1
Given that T has N1 vertices of degree 1, N2 vertices of degree 2, N3 vertices
of degree 3, ……….. Nk vertices of degree k.
Then by HSP,
the sum of the degrees of the vertices = twice the number of edges.
 ( N1 1)  ( N 2  2)  ( N 3  3)  .......  ( N k  k )  2 ( N1  N 2  N 3  .....  N k  1)

 N1  2 N 2  3N 3  4 N 4  .......  k N k  2 N1  2 N 2  2 N 3  2 N 4  .....  2 N k  2

 N 3  2 N 4  .......  (k  2) N k  2  N1

 N1  2  N 3  2 N 4  .......  (k  2) N k
Available At VTU HUB (Android App)
Q7: If a tree has 4 vertices of degree 3, 2 vertices of degree 4 and 1
vertex of degree 5, then find the number of pendant vertices in T.
Solution:
Let N be the number of pendant vertices in T (i.e., vertices of degree 1).
Therefore, total number of vertices = N + 4 + 2 + 1 = N + 7.
Thus total number of edges = (N + 7) – 1 = N + 6 .
Given that T has 4 vertices of degree 3, 2 vertices of degree 4 and 1 vertex
of degree 5, then by HSP,

 deg v  2
vV
E

 ( N 1)  (4  3)  (2  4)  (1 5)  2 ( N  6)

 N  25  2 N  12

 N  13
Thus the given tree has 13 pendant vertices.
Available At VTU HUB (Android App)
PRACTiCE QuEsTions:

 If a tree has 4 vertices of degree 2, 1 vertex of degree 3, 2


vertices of degree 4 and 1 vertex of degree 5. Find the number
of leaves in T.

 Suppose that a tree T has 2 vertices of degree 2, 4 vertices of


degree 3 and 3 vertices of degree 4. Find the number of
pendant vertices in T.

Available At VTU HUB (Android App)


Rooted Tree: A directed tree T is called a rooted tree if (i) T contains a
unique vertex called the root whose in degree is equal to 0 and (ii) The in
degrees of all other vertices of T are equal to1.

Ex:

Rooted tree Not a rooted tree

Level number: A vertex v of a rooted tree is said to be at the kth level or


has level number k if the path from r to v is of length k.

Note:
 If v1 and v2 are two vertices such that v1 has a lower level number than v2
and there is a path from v1 to v2 then we say that v1 is an ancestor of v2 or
that v2 is a descendant of v1.
Available At VTU HUB (Android App)
 If v1 and v2 are such that v1 has a lower level number than v2 and there is a
direct edge from v1 to v2, then v1 is called the parent of v2 or v2 is called
child of v1.
 Two vertices with common parent are referred as siblings.
 A vertex whose out degree is 0 is called a leaf.
 A vertex which is not a leaf is called an internal vertex.

Ex :
v1, v2 are at the first level. v3, v4 are at
the second level. v5, v6, v7 are at the
third level. v8, v9 are at the fourth level.
v1 is the ancestor of v3, v5, v6 (or) v3,
v5, v6 are the descendant of v1.

v1 is the parent of v3 (or) v3 is the child of v1.


v5, v6 are siblings and v8, v9 are siblings.
v5, v6, v8, v9 are leaves and all other vertices are internal vertices.
Available At VTU HUB (Android App)
m – ary tree: A rooted tree T is called a m – ary tree if every internal
vertex of T is of out degree <= m. i.e, if every internal vertex of T has at
most m children.
Complete m – ary tree: A rooted tree T is called a complete m – ary tree
if every internal vertex of T is of out degree m i.e, every internal vertex of T
has exactly m children.
Binary tree: A m – ary tree for which m = 2 is called a binary tree. In other
words, a rooted tree T is called a binary tree if every vertex of T is of out
degree <= 2 i.e, every vertex has at most two children.
Complete Binary tree: A rooted tree T is called a complete binary tree if
every internal vertex of T is of out degree 2 i.e., if every internal vertex has
exactly two children.

Ex :

Binary tree Complete


Available Binary
At VTU HUB tree App)
(Android
Balanced tree: If T is a rooted tree and h is the largest level number
achieved by a leaf of T, then T is said to have height h . A rooted tree of
height h is said to be balanced tree if the level number of every leaf is
h or h – 1.

Ex :

Balanced Not Balanced

Full Binary tree: Let T be a complete binary tree of height h. Then T is


called a full binary tree if all the leaves in T are at the level h.

Ex :

Available At VTU HUB (Android App)


PRoblEms:
Q1: Let T be a complete m - ary tree of order n with p leaves and q
internal vertices, prove that
mp  1
(i ) n  mq  1 
m 1
(m  1)n  1
(ii ) p  (m  1)q  1 
m
n 1 p 1
(iii ) q  
m m 1
Solution: Given that T is a complete m - ary tree.
This implies, every internal vertex is of out-degree m.
Since every vertex in a rooted tree is either a leaf or an internal vertex, the
total number of vertices in T is the sum of number of leaves in T and number
of internal vertices in T.
i.e., n  p  q       (1)
Available At VTU HUB (Android App)
WKT, out – degree of every leaf is zero and out – degree of every internal
vertex is m.
This implies, Sum of out – degrees of all vertices in T

 ( p  0)  (q  m)  qm       (2)

WKT, in a rooted tree of order n, the in – degree of the root is zero and the
in – degrees of the remaining (n – 1) vertices are 1 each.
This implies, Sum of in – degrees of all vertices in T

 (1 0)  (n  1)  1  n  1       (3)
Therefore, by first theorem of digraph theory,
Sum of in – degrees = sum of out – degrees
i.e., n 1  qm
n 1
 n  mq  1      (i)  q      (ii)
m
Available At VTU HUB (Android App)
Substituting equation (i) in equation (1),
mq 1  p  q
 p  (m  1)q  1      (iii)

p 1
 q      (iv)
m 1
Substituting equation (iv) in equation (i),
( p  1)
n m 1
(m  1)
m( p  1)  (m  1)
 n
(m  1)
mp  1
 n      (v)
m 1

Available At VTU HUB (Android App)


mp  1
From (v), we have n 
m 1

 (m  1) n  mp  1

(m  1) n  1
 p      (vi)
m

Equations (i) to (vi) give the required proofs.

Available At VTU HUB (Android App)


Note:
 For a complete binary tree, i.e., m = 2, the above results are:
(i ) n  2q  1  2 p  1
n 1
(ii ) p  q  1 
2
n 1
(iii ) q   p 1
2
 Alternate notation:
Let T = (V, E) be a complete tree with |V| = n. If T has ‘l’ leaves and ‘i’
internal vertices, then
m .l  1
(i ) n  m . i  1 
m 1
(m  1) . n  1
(ii ) l  (m  1) . i  1 
m
n 1 l 1
(iii ) i  
m m  1 Available At VTU HUB (Android App)
Q2: Find the number of leaves in a complete binary tree if it has 29
vertices.
Solution:
For a complete binary tree, we have m = 2.

Given n = 29 , p = ?

For a complete binary tree, we have


n 1
p
2
29  1
 p  15
2

Number of leaves = p = 15.

Available At VTU HUB (Android App)


Q3: Find the number of internal vertices in a complete 5 – ary tree with
817 leaves. Hence find its order.
Solution:
Given m = 5 ; p = 817 ; q = ?
p 1
we have , q 
m 1
817  1 816
 q 
5 1 4
 q  204
Thus given tree has 204 internal vertices.
We have, order  n  mq  1
 n  (5  204)  1

 n  1021
Available At VTU HUB (Android App)
Q4: A complete binary tree has 20 leaves. Find the number of vertices.

Solution:
For a complete binary tree, m = 2.

By data, p = 20.

mp  1
we have , n 
m 1

(2  20)  1
 n
2 1

 n  39

Thus the number of vertices = n = 39.

Available At VTU HUB (Android App)


Q5: A classroom contains 25 microcomputers that must be connected
to a wall socket that has 4 outlets. Connections are made by using
extension cords that have 4 outlets each. Find the least number of cords
needed to get this computer set up for the class.
Solution:
Let us treat the wall socket as the root of a complete 4 – ary tree with the
computers as its leaves and the internal vertices other than the root
as the extension cords.

 m  4 , p  25
p  1 24
Thus, number of internal vertices = q   8
m 1 3

Therefore, number of extension cords needed (excluding the root) is


q – 1 = 8 – 1 = 7.

Available At VTU HUB (Android App)


The computer set up can be represented as below:

Available At VTU HUB (Android App)


PRACtiCE QuEstions:

 A complete 3 – ary tree has 34 internal vertices. How many leaves


does T have?

 The computer laboratory of a school has 10 computers that are to


be connected to a wall socket that has 2 outlets. Connections are
made by using extension cords that have 2 outlets each. Find the
least number of cords needed to get this computer set up for use.

 Which of the following is a balanced tree? Full binary tree?

Available At VTU HUB (Android App)


Sorting:

The method of splitting and merging, done by the use of


balanced complete trees is known as merge sort.

The process of 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 possible to half), until
each sub-list contains a single element.

 In the second part, we merge the sub-lists in non – decreasing


order until the original ‘n’ integers have been sorted.

Available At VTU HUB (Android App)


Problems:
Apply merge – sort to the following lists:
Q1: - 1, 7, 4, 11, 5, -8, 15, -3, -2, 6, 10, 3 .
Solution: Split:
{- 1, 7, 4, 11, 5, -8, 15, -3, -2, 6, 10, 3}

{- 1, 7, 4, 11, 5, -8} {15, -3, -2, 6, 10, 3}

{- 1, 7, 4} {11, 5, -8} {15, -3, -2} {6, 10, 3}

{- 1, 7} {4} {11, 5} {-8} {15, -3} {-2} {6, 10} {3}

{-1} {7} {11} {5} {15} {-3} {6} {10}

(Already single elements, later while merging we consider in 2 nd step)


Available At VTU HUB (Android App)
Merge:
{-1} {7} {11} {5} {15} {-3} {6} {10}

{- 1, 7} {4} {5, 11} {-8} {-3, 15} {-2} {6, 10} {3}

{- 1, 4, 7} {-8, 5, 11} {-3, -2, 15} {3, 6, 10}

{- 8, -1, 4, 5, 7, 11} {-3, -2, 3, 6, 10, 15}

{- 8, -3, -2, -1, 3, 4, 5, 6, 7, 10, 11, 15}

Thus Sorted version of the given list is:


- 8, -3, -2, -1, 3, 4, 5, 6, 7, 10, 11, 15.
Available At VTU HUB (Android App)
Q2: -9, 6, 5, -3, 4, 2, -7, 6, -5, 10, -11, 0, 1 .
Solution: Split:
{-9, 6, 5, -3, 4, 2, -7, 6, -5, 10, -11, 0, 1}

{- 9, 6, 5, -3, 4, 2, -7} {6, -5, 10, -11, 0, 1}

{- 9, 6, 5, -3} {4, 2, -7} {6, -5, 10} {-11, 0, 1}

{- 9, 6} {5, -3} {4, 2} {-7} {6, -5} {10} {-11, 0} {1}

{-9} {6} {5} {-3} {4} {2} {6} {-5} {-11} {0}

(Already single elements, later while merging we consider in 2nd step)

Available At VTU HUB (Android App)


Merge:
{-9} {6} {5} {-3} {4} {2} {6} {-5} {-11} {0}

{- 9, 6} {-3, 5} {2, 4} {-7} {-5, 6} {10} {-11, 0} {1}

{- 9, -3, 5, 6} {-7, 2, 4} {-5, 6, 10} {-11, 0, 1}

{- 9, -7, -3, 2, 4, 5, 6} {-11, -5, 0, 1, 6, 10}

{-11, -9, -7, -5, -3, 0, 1, 2, 4, 5, 6, 10}

Thus Sorted version of the given list is:


-11, -9, -7, -5, -3, 0, 1, 2, 4, 5, 6, 10.
Available At VTU HUB (Android App)
PRACtiCe QUestiONs:

 -1, 3, 8, 4, 5, 10, 6, 2, 9

 -1, 0, 2, -2, 3, 6, -3, 5, 1, 4

Available At VTU HUB (Android App)


Binary Sequence:
A sequence consisting of only 0 and 1 is called a binary sequence or a
binary string.
The number of elements contained in a sequence is called its length.
Ex: 01, 001, 101, 11001, 1000100 are binary sequences of lengths 2, 3, 3,
5, 7 respectively.
Prefix Codes:
Let P be a set of binary sequences that represent a set of symbols. Then P is
called a prefix code if no sequence in P is a prefix of any other sequence in P.
Ex: P = {10, 0, 1101, 111, 1100}, Q = {000, 001, 01, 10, 11} are prefix
codes, whereas the sets A = {01, 0, 101, 10, 1}, B = {1, 00, 01, 000, 0001}
are not prefix codes.
 Prefix codes can be represented as binary tree by constructing a full
binary tree of height equal to length of longest sequence in the code and
assign symbol 0 to every edge that is directed towards the child in the left
from its parent vertex and symbol 1 to every edge that is directed towards the
child in the right.
Available At VTU HUB (Android App)
Weighted Trees:
Consider a set of positive integers w1, w2, w3, …… wn where
w1  w2  w3  .......  wn . Suppose we assign these integers to the n leaves of a
complete binary tree T = (V, E) in any one to one manner. The resulting tree
is called a complete weighted binary tree with w1, w2, w3, …… wn as
weights.

 If l(wi) is the level number of the leaf of T to which the weight wi is


assigned, then w(T) is called the weight of the tree T defined by
n
w(T)   w  l (w )
i 1
i i

Optimal Tree:
Given a set of weights, consider the set of all complete binary trees to whose
leaves, these weights are assigned. A tree in this set which carries the
minimum weight is called an optimal tree for the weights.

 For a given set of weights there can be more than one optimal tree.
Available At VTU HUB (Android App)
Huffman’s Procedure:
An optimal tree for a given set of weights can be constructed as follows:

 Arrange the weights in non-decreasing order and assign them to isolated


labeled vertices.

 Select two vertices with minimum weights. Add these vertices to get a
new vertex. Draw a tree with new vertex as root and the selected vertices
as children. Leave the other vertices undisturbed.

 Repeat the procedure in step 2, till all the vertices and (sub) trees are
connected to get a complete weighted binary tree.

 The tree obtained is the optimal tree for the given set of weights and is
also known as Huffman’s tree. This tree is not unique.

Available At VTU HUB (Android App)


Optimal Prefix Code:
 Huffman’s tree (optimal tree) can be used to obtain a prefix code for the
symbols representing its leaves.

 For this purpose, we first label the symbols 0, 1 to its edges by labeling
procedure indicated earlier.

 Then all vertices and the leaves of tree can be identified by binary
sequences.

 The binary sequences through which the leaves are identified yield a
prefix code for the symbols representing the leaves.

 This prefix code is known as optimal prefix code.

 As optimal tree is not unique, the optimal prefix code is also not
unique.

Available At VTU HUB (Android App)


Problems:
Q1: Construct an optimal tree for a given set of weights
{4, 15, 25, 5, 8, 16}. Hence find the weight of the optimal tree.
Solution:
Arranging the given weights in non – descending order and associating with
the vertices a, b, c, d, e, f , we get

Step 1:
a ( 4) b (5) c (8) d (15) e (16) f (25)

v1 (9)
Step 2:
c (8) d (15) e (16) f (25)

a ( 4) b (5)

Available At VTU HUB (Android App)


v2 (17)
Step 3:
f (25)
d (15) e (16)
v1 (9)
c (8)

a ( 4) b (5)

v2 (17) v3 (31)
Step 4:
f (25)
v1 (9) d (15) e (16)
c (8)

a ( 4) b (5)

Available At VTU HUB (Android App)


v3 (31) v4 (42)

Step 5:
v2 (17)
f (25)
d (15) e (16)
v1 (9)
c (8)

a ( 4) b (5)

v5 (73)

Step 6:
v3 (31) v4 (42)

 Optimal tree
v2 (17) f (25)
d (15) e (16)
v1 (9)
c (8)

a (HUB
Available At VTU b (5App)
4) (Android )
Thus the weight of the tree is:

w (T)  (4  4)  (5  4)  (8  3)  (15  2)  (16  2)  (25  2)


     
a b c d e f

 w (T)  172 .

Available At VTU HUB (Android App)


Q2: Construct an optimal prefix code for the symbols a, o, q, u, y, z that
occur with frequencies 20, 28, 4, 17, 12, 7 respectively.
Solution:
Arranging these symbols along with their frequencies in non – descending
order, treating frequencies as the weights and the corresponding symbols as
the isolated vertices, we get

Step 1:
q (4) z (7) y (12) u (17) a (20) o (28)

v1 (11)
Step 2:
y (12) u (17) a (20) o (28)

q ( 4) z (7 )

Available At VTU HUB (Android App)


v2 ( 23)
Step 3: u (17) a (20) o (28)
v1 (11)
y (12)

q (4) z (7 )

v2 ( 23)
v3 (37)

Step 4: o (28)
v1 (11)
y (12)
u (17) a (20)

q (4) z (7 )

Available At VTU HUB (Android App)


v3 (37) v4 (51)
Step 5:
v2 (23)
u (17) a (20) o (28)
v1 (11)
y (12)

q (4) z (7 )

v5 (88)

v3 (37) v4 (51)
Step 6:
 Optimal tree
v2 (23)
u (17) a (20) o (28)
v1 (11)
y (12)

qAvailable
( 4) z (7At) VTU HUB (Android App)
Rewriting the obtained optimal tree(Huffman tree), let us assign 0’s
and 1’s to the edges using labeling procedure as below:

0 1

0 1 0 1

u a 0 1 o

0 1 y

q z

Thus the optimal prefix code for the given symbols is:
a : 01 o : 11 q : 1000
u : 00 y : 101 z : 1001

Available At VTU HUB (Android App)


Q3: Obtain an optimal prefix code for the letters of the word
ENGINEERING. Hence indicate the code.
Solution:
Given word consists of the letters E, N, G, I, R with frequencies 3, 3, 2, 2, 1
respectively.
Arranging these letters along with their frequencies in non – descending
order, treating frequencies as the weights and the corresponding letters as
the isolated vertices, we get

Step 1:
R (1) G ( 2) I (2) E (3) N (3)

Step 2: v1 (3)

I (2) E (3) N (3)

R G
Available At VTU HUB (Android App)
v1 (3) v2 (5)

Step 3: N (3)

R G I E

Step 4: v2 (5) v3 (6)

v1
I E N

R G

Available At VTU HUB (Android App)


v4 (11)

Step 5: 0 1
v2 v3  Optimal tree
0 1 0 1
v1
I E N 0 1

R G

Let us assign 0’s and 1’s to the edges using labeling procedure.
Now, the code for the letters(symbols) involved in the given word
(i.e., leaves of the optimal tree) is:

E : 01 N : 10 G : 111 I : 00 R : 110

Thus code for ENGINEERING is: 0110111001001011100010111

Available At VTU HUB (Android App)


Q4: Obtain an optimal prefix code for the message ROAD IS GOOD.
Indicate the code.
Solution:
The given message consists of the letters R, O, A, D, I, S, G with frequencies
1, 3, 1, 2, 1, 1, 1 respectively.
Also there are 2 blank spaces ( ) between the words of the message .
Arranging these symbols(including blank spaces) along with their
frequencies in non – descending order, treating frequencies as the weights
and the corresponding symbols as the isolated vertices, we get

Step 1:
R (1) A (1) I (1) S (1) G (1) D ( 2) O (3)

v1 (2)
Step 2:
I (1) S (1) G (1) D ( 2) O (3)

Available At VTU HUB (Android App) R A


v1 (2) v2 ( 2)
Step 3:
G (1) D ( 2) O (3)

R A I S

v1 (2) v2 (2) v3 (3)


Step 4:
O (3)

R A I S G D

v2 (2) v3 (3) v4 (4)


Step 5:
O (3)
v1
G D
I S

R A
Available At VTU HUB (Android App)
v3 (3) v4 (4) v5 (5)

Step 6:
v1 v2
G D O

R A I S

v5 (5) v6 (7)
Step 7:

v2 v3 v4
O
v1
I S G D

R A
Available At VTU HUB (Android App)
v7 (12)

0 1
Step 8:
v5 v6  Optimal tree
0 1 0 1
v2 v3 v4
0 1 O 0
0 1 1
v1
I S G D 0 1

R A
Code for the symbols(i.e., leaves of the optimal tree):
R : 1110 O : 01 A : 1111 D : 101
I : 000 S : 001 G: 100 : 110
Code for the message ROAD IS GOOD is:
11100111111011100000011101000101101
Available At VTU HUB (Android App)
PRACtiCe QUestiONs:

 Obtain an optimal prefix code for the symbols A, B, C, D, E, F, G, H,


I, J that occur with the frequencies:
78, 16, 30, 35, 125, 31, 20, 50, 80, 3.

 Obtain an optimal prefix codes for the letters of the following


messages and hence indicate the code:
(i) FALL ON THE WALL
(ii) LETTER RECEIVED
(iii) MISSION SUCCESSFUL

Available At VTU HUB (Android App)

You might also like