Dms Module 5
Dms Module 5
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:
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:
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.
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.
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)
(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.
Consider m = rs
72 = r*12
This gives r = 6.
Solution:
For a bipartite graph, we have 4m n 2 (1)
Given V n 4 and E m 5
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.
1
For a complete graph, m n (n 1)
2
For a complete bipartite graph Kr, s , there are r + s vertices and r*s
edges.
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
vV
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.
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.
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.
38 4n
38
n 9.5 10
4
i.e., n V 10
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
n6
(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
vV
3n 6 12
3 n 18 n6
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
vV
d1 d 2 d 3 ..... d n 2m (1)
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
2m
n
2m
i.e., (3)
n
Thus combining equations (2) and (3), we get
2m
n
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.
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.
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
Thus G1 G2
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.
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.
1.
2.
4.
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.
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
Ex:
G K4 G
Self Complementary graphs: A simple graph G which is isomorphic to its
complement is called a self complementary graph.
Ex: GG
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
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 4, 5 shown above are not trees since the 4th graph contains a
cycle, whereas the 5th one is not connected.
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.
deg(v) 2 E
vV
d1 d 2 d 3 ...... d n 2(n 1)
d1 d 2 d 3 ...... d n 2n 2 (1)
d 2 d 3 ...... d n 2n 2 1
d 2 d 3 ...... d n 2n 3 (2)
d 2 d 3 ...... d n 2( n 1)
d 2 d 3 ...... d n 2n 2
mnk
nmk
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
E V 1 399
2 399
798 .
deg v 2
vV
E
(k 1) (n k ) 3 2 (n 1)
k 3n 3k 2n 2
n 2k 2
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
vV
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:
Ex:
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.
Ex :
Ex :
Ex :
( 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
(m 1) n mp 1
(m 1) n 1
p (vi)
m
Given n = 29 , p = ?
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
m 4 , p 25
p 1 24
Thus, number of internal vertices = q 8
m 1 3
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.
{- 1, 7} {4} {5, 11} {-8} {-3, 15} {-2} {6, 10} {3}
{-9} {6} {5} {-3} {4} {2} {6} {-5} {-11} {0}
-1, 3, 8, 4, 5, 10, 6, 2, 9
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:
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.
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.
As optimal tree is not unique, the optimal prefix code is also not
unique.
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)
a ( 4) b (5)
v2 (17) v3 (31)
Step 4:
f (25)
v1 (9) d (15) e (16)
c (8)
a ( 4) b (5)
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) 172 .
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 )
q (4) z (7 )
v2 ( 23)
v3 (37)
Step 4: o (28)
v1 (11)
y (12)
u (17) a (20)
q (4) z (7 )
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
Step 1:
R (1) G ( 2) I (2) E (3) N (3)
Step 2: v1 (3)
R G
Available At VTU HUB (Android App)
v1 (3) v2 (5)
Step 3: N (3)
R G I E
v1
I E N
R G
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
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)
R A I S
R A I S G D
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: