3. Graph Theory
3. Graph Theory
Definition
O(G) = 4
V = {P, Q, R, S} Size(G) = 5
E = {x1, x2, x3, x4}
Self loop:
Terminologies: It is an edge in the graph which has same
There are some terminologies in graph end points, i.e., it connects a vertex to itself.
theory:
Adjacent vertices:
Two vertices v and u, belonging to vertex set Parallel edges (multiple edges):
V of an undirected graph G(V,E), are adjacent If in a graph between two vertices, if more
if there exists an edge e, such that e belongs than one edge is there, then those edges are
to set E and connects the vertices u and v. known as parallel edges.
The graph, which contains parallel edges is
known as multigraph.
Graph Theory 55
Multiple edges from c to d are shown by e1 Simple graph:
and e2 in the diagram. Simple graph can be defined as an undirected,
unweighted graph having no self loops and
multiple/parallel edges.
Note:
Isolated vertex:
An isolated vertex does not have any vertex
adjacent to it, i.e., it is a vertex with degree (I)
(II)
zero.
Fig. 3.2 Non-Simple Graphs (I) with Multiple Edges
Example: Consider the following figure: (II) with Self Loops
56 Graph Theory
Multigraph:
Graphs that may have multiple/parallel edges
and no self loops are called multigraphs.
1. Simple graph
Directed graph:
If in a graph all the edges are ordered edges,
i.e., edges with direction then the graph is
known as directed graph, i.e., edge from
vertex v to u is not same as edge from vertex
u to v. It has undirected edges, no multiple
⇒
edges, no self loops.
2. Multigraph
Here, V = {A, B, C, D}
E = {(A, B), (B, D), (D, C), (C, A)}
Graph Theory 57
a) It has directed edges. For each self loop the degree is counted as 2.
b) N
o multiple edges, first is from c to d
and second is from d to c. Min-degree: Least among the degrees of all
c) It has 2 self loops (on c and e). given vertices, represented by d.
a 2
b 3
Rack Your Brain
c 2
Describe a graph model that can be
d 3
used to represent all forms of electronic
communication between two people in d(G) = 2 and D(G) = 3.
a single graph. What kind of graph is
needed? Note:
Let G be a simple undirected graph with
Degree of vertex: v-vertices and e-edges.
The number of edges that are incident onto x
a vertex is termed as the degree of that
( 1-x )
2
vertex.
Solved Examples
=i 1=i 1
∑
deg + (Vi )
= ∑
deg − (Vi ) |E |
=
Note:
i.e., for a directed graph sum of all the out
y A loop at a vertex contributes one to
degrees of vertices is equal to sum of all
both the in-degree and the out degree
in degrees of the vertices, which is equal to
of this vertex.
number of edges in the graph because in
y As each edge has an initial vertex and
directed graph every edge will be counted as
a terminal vertex, the sum of the in-
in degree for some vertex and out degree for
degree and the sum of the out-degree
some other vertex.
of all vertices in a graph with directed
where e = number of edges in the graph.
edges are the same. Both of these
deg(V) = in-degree(V) + out-degree(V)
sums are the number of edges in the
Corollary 2: In an undirected graph, the
graph.
number of odd degree vertices are even.
Example:
Graph Theory 59
Corollary 5: If G is an undirected graph with Consider the degree sequences S1 and S2,
degree of each vertex atmost k (≤ k) then and assume that S1 is in descending order.
k*|v| ³ 2|E|. S1: {S, t1, t2, … tS, d1, d2, …, dn}
S2: {t1 – 1, t2 – 1, …, tS – 1, d1, d2, … dn}
Example: S1 is graphic & S2 is graphic.
Steps involved in this theorem:
y Sort given degree sequence in descending
order.
y Pick the largest element and remove it
from the list.
y Construct a new list.
2×4³2×4 y Take number of elements = largest
element chosen.
Degree sequence: y Subtract 1 from all the taken elements.
y Arrangement of degree of all the vertices y Check if obtained degree sequence is valid
either in ascending or descending order, or not (say this S2).
the sequence then obtained is called y S1 is a valid graphical degree sequence if
degree sequence. S2 is a valid graphical sequence.
y In any undirected graph, if degree of each y Repeat steps 1-7.
vertex is distinct, then simple graph does
not exist. Points to remember:
y If we get atleast one negative term in
Havell-Hakimi theorem: degree sequence, then simple graph does
The purpose of this theorem is to check if a not exist for the given degree sequence.
given degree sequence is a degree sequence y When there are not enough degree present
of a simple graph or not. in the degree sequence, then also simple
graph does not exist.
Solved Examples
60 Graph Theory
4. <8, 7, 7, 6, 4, 2, 1, 1>, determine whether Some special simple graphs:
the given degree sequence represents a Null graph:
simple undirected graph. A graph having ‘V’ vertices and zero edges is
Solution: known as null graph.
In the above given degree sequence, after
choosing 8 we need to subtract 1 from 8 Trivial graph:
elements out of remaining elements but Trivial graph consists of one vertex and zero
there are only 7 elements left. Therefore, edges.
given degree sequence is not valid sequence Regular graph:
for simple undirected graph. A graph in which all the vertices have same
OR degree is known as regular graph.
Solution:
Note:
Note:
In a simple graph with n vertices at least
The undirected graph that results from
ignoring directions of edges is called the two vertices should have same degree.
underlying undirected graph.
Complete graph:
A simple graph with V vertices where every
vertex has an edge with all the other vertices
Previous Years’ Question is known as complete graph. The graph kn,
for n = 1, 2, 3, 4, 5, 6 as shown in the given
The degree sequence of a simple graph figure.
is the sequence of the degrees of the
nodes in the graph in decreasing order.
Which of the following sequences can
not be the degree sequence of any
graph? [GATE CSE 2010]
I. 7, 6, 5, 4, 4, 3, 2, 1
II. 6, 6, 6, 6, 3, 3, 2, 2
III. 7, 6, 6, 4, 4, 3, 2 ,2
IV. 8, 7, 7, 6, 4, 2, 1, 1
(A) I and II (B) III and IV
(C) IV only (D) II and IV
Solution: (D)
Graph Theory 61
Wheel graph:
Note:
Wheel graph represented by wn, where n is
y A complete graph is a simple graph greater than or equal to four, can be obtained
with maximum number of edges. by adding a vertex to the cycle graph such
y A complete graph is a simple graph that the new vertex is adjacent to all vertices.
with every vertex having maximum
degree.
Cycle graph:
The cycle graph Cn, for n ≥ 3, is a simple
connected graph with degree of every vertex
as 2.
Note:
Number of edges in Wn = 2(n - 1)
Cyclic graph:
A cyclic graph is a simple graph which
contains atleast one cycle.
Acyclic graph:
Simple graph having no cycle is known as
acyclic graph.
Note:
If a graph is a cycle graph then number of
vertices is equal to number of edges but
not vice versa.
62 Graph Theory
Bipartite graph:
Solution:
The vertex set of the following graph can be
Definition partitioned into two sets, V1 = {a,b,d} and V2
= {c,e,f,g}.
"A simple graph G is called a bipartite
graph if its vertex set V can be partitioned Since, there is no edge between the vertices
into two disjoint sets V1 & V2 such that of same set, so the given graph is bipartite
every edge in the graph connects a graph.
vertex in V, and a vertex in V2 (so that no
edge in G connects either two vertices Note:
in V1 or two vertices in V2). When this
y A simple graph is bipartite if and only
condition holds, we call the pair (V1, V2 )
if it is possible to assign one of two
a bipartition of the vertex set V of G." different colours to each vertex of the
graph so that no two adjacent vertices
Example: are assigned he same colour.
Consider the following cyclic graph C6. The y A graph is bipartite iff it has no odd
length cycle.
vertex set of C6 can be partitioned into two
sets V1 = {1,3,5} and V2 = {2,4,6}, such that
Complete bipartite graph:
there is no edge between vertices of same
The complete bipartite graph Km,n is a graph
set: therefore C6 is a bipartite graph.
in which vertex set V is divided into two
subsets, P having m vertices and Q having n
vertices respectively, such that every vertex
from set P is connected to every other vertex
1 • • 2
in set Q and there is no edge between the
vertices from same subset.
3 • • 4
Example:
5 • • 6
Note:
Km, n has (m + n) vertices and m*n edges.
Graph Theory 63
Rack Your Brain
Star graph:
Star graph is a special type of graph in which
a single vertex is connected to all the other
vertices.
For a graph having n vertices, n – 1 vertices
will have degree 1 and one vertex will have
degree n – 1.
It is represented as: k(1, n – 1). Connected graph:
y Used in client server architecture. y A graph having V vertices and E edges,
is said to be connected if there is a path
between all the pairs of vertices in the
graph.
y Maximally connected subgraph of a graph
is a component.
y Every connected graph has exactly one
component.
y If G is a simple graph with n vertices, e
edges, and k components.
Hypercube graph/n dimensional cube:
(n − k) (n − k + 1)
In hypercube graph, there is an edge between n−k ≤ e ≤
two vertices only if the vertices differ by 2
single bit position. Examples of connected graph:
y The hypercube graph is represented by Qn.
y Order of hypercube graph O(Qn) = number
of vertices = 2n
y Qn is a n degree regular graph.
y Number of edges in Qn = n × 2n–1 (using
handshaking lemma i.e., in every finite
undirected graph, the number of vertices Fig. 3.6 Connected Graphs
that touch an odd number of edges is
even).
64 Graph Theory
Disconnected graph: Example: Consider a simple graph G having
For a disconnected graph (k > 1 or k ³ 2), 8 vertices and 15 edges. Calculate the number
the path is not available between atleast one of edges in G (|E( G )|).
pair of vertices. Solution:
We have
Examples of disconnected graph:
|E(G)| + |E( G )| = |E(kn)|
n(n − 1) 8 × 7
15 + |E( G )| = = = 28
2 2
|E( G )| = 28 – 15
|E( G )| = 13
Self complementary:
When a graph is isomorphic to its complement
Fig. 3.7 Disconnected Graphs is called self complementary graph.
Note:
y If G is a simple graph with n-vertices
Graph Theory 65
The following graph is subgraph of K5. Union of graphs:
Two or more graphs can be combined in
various ways; the new obtained graph after
combining all the vertices and edges is called
the union of graph(s).
Definition
The union of two simple graphs G1 = (V1,
E1) and G2 = (V2, E2) is a simple graph
with vertex set V, u V2 and edge set E1 u
E2• The union of G1 and G2 is denoted by
G1 u G2.
Solved Examples
Example:
Solution:
The vertex set of G1 ∪ G2 is the
union of the two vertex sets, namely,
{a, b, c, d, e, f}. The edge set of G1 ∪ G2 is the
union of the two edge sets.
66 Graph Theory
Solution:
Initial Vertex Terminal Vertices For the given directed graph, the adjacency
list representation will be as follows:
a b, c, e
Initial Vertex Terminal Vertices
b a
a b, c, d, e
c a, d, e
b b, d
d c, e
c a, c, e
e a, c, d
d
Fig. 3.11 An Adjacency List
1 if {i, j} is anedge of G
aij =
0 otherwise
Solved Examples
Graph Theory 67
9. Represent the following graph with an
incidence matrix.
Rack Your Brain
Solution:
The incidence matrix for above graph is:
Note:
Incidence matrix can also be used to
represent multiple edges and self loops.
Multiple edges are represented in the
incidence matrix using columns with
identical entries. Loops are represented
using a column with exactly one entry
= 1, corresponding to the vertex that is Walk, trail, circuit, path, and cycle:
incident with this loop. Walk:
A walk is an alternative sequence of vertices
and edges, which begins and end with a
vertex. Both edges and vertices can be
repeated in a walk.
68 Graph Theory
Trail: It is also called cycles.
A walk is said to be a trail when there is
no repetition of edges, but vertex can be
repeated.
Closed trail:
A trail starting and ending at the same vertex
is known as a closed trail.
A closed trail is called a circuit.
Note:
A cycle is a part of circuit but a circuit
can’t always be a cycle.
Euler graph:
If a graph contains Euler circuit, then it is
known as an Euler graph.
Or
A graph is an Euler graph if it has a closed
trail containing all edges. The above graph has Euler circuit V1 – e1 – V2
– e9 – V8 – e8 – V6 – e11 – V4 – e10 – V2 – e2 –
V3 – e3 – V4 – e4 – V5 – e5 – V6 – e6 – V7 – e7
– V8 – e12 – V1
Graph Theory 69
Solved Examples
70 Graph Theory
Solved Examples
Example:
Euler’s formula:
As we have already seen, a planar graph
splits the plane into regions, including an
Planar graph:
unbounded region. According to Euler, for any
y A graph having a planar representation is
simple connected graph having ‘V’ vertices
called a planar graph.
and ‘e’ edges, the number of regions ‘r’ in the
y Planar representation means drawing a planar representation of graph is given by:
graph on a plane without crossing the V–e+r=2
edges.
y The planar representation of a planar
graph divides the entire plane into regions
or faces.
Graph Theory 71
Polyhedral graph:
A planar graph in which every interior region Rack Your Brain
is polygon is called polyhedral graph.
y In a polyhedral graph degree of every Determine which of the following graphs
vertex, i.e., deg(V) ³ 3 ∀ V ∈ G are planar?
y For a polyhedral graph, the following
inequality must hold:
| V – e + r = 2
| 3r ≤ 2e
| e ≤ 3V – 6
Note:
y K5 is a non planar graph with minimum number of vertices.
y K3.3 is non planar graph with minimum number of edges.
Solved Examples
Solution:
G1 is planar because it can be represented
without edge crossings.
72 Graph Theory
13. Suppose that a connected planar Tree can be defined as a minimally connected
simple graph has 10 vertices, each of acyclic graph.
degree 3. Into how many regions does a For every (u, v), there exists exactly one
representation of this planar graph split path between u and v or it is a 1-connected
the plane? graph.
Solution: Every tree is bi-chromatic and bipartite.
Using Handshaking theorem, S degree (V) = 2
× number of edges Fundamental cycle:
A cycle obtained by adding a single edge is
3 * 10 = 2 × e
called a fundamental cycle.
e = 15
Now, number of fundamental cycles = nc2
From Euler’s formula the number of region
when n = number of vertices.
is
r=e–v+2
Rooted tree:
r = 15 – 10 + 2
A tree with a specific vertex is chosen as a
r=7
root.
Kuratowski’s theorem:
“If a graph is planar, so will be any graph
obtained by removing an edge {u, v} and
adding a new vertex w together with edges
{u, w} and {w, u}. Such an operation is called
an elementary subdivision. The graphs G1 =
(V1, E1), G2 = (V2, E2) are called homeomorphic
if they can be obtained from the same graph
by a sequence of elementary subdivision.” Root, siblings (having a common parent), leaf
node can be only defined for a rooted tree.
A graph is planar if it does not contain any
graph homeomorphic to K5 or K3,3. depth (u) = distance (u, root), where u is node
height (T) = Maximum of depth (u), where u
is node and T is a tree
level (u) = 1 + depth (u)
Rack Your Brain
OR
Determine whether the given graph is level (T) = 1 + height (T), where u is node and
homeomorphic to K3, 3. T is a tree
K-ary tree:
It is a rooted tree.
0 ≤ number of children (u) ≤ k
Trees:
Basically, this is the topic of data structure
and algorithms but here, we will study this
topic in terms of Discrete Mathematics.
Graph Theory 73
Full k-ary tree: kh+ 1 − 1
y It is a rooted tree. 2. n ≤
k−1
y Number of children (u) = 0 or k h
k −1
3. i ≤
k−1
For minimum number:
1. n ³ h + 1
2. i ³ h
3. log kl ≤ h
Spanning tree:
A spanning tree of G is a subgraph of G which
Complete k-ary tree: includes every vertex of G.
y It is a rooted tree.
y All levels except the last one are Note:
completely filled. Every connected graph has a spanning
y Last level is left adjusted. tree.
Solution:
74 Graph Theory
Example: Number of spanning trees in a complete
graph
= nn–2 (Cayley’s formula)
= 16
Kirchoff’s theorem:
Circuit rank (G) = m – (n – 1) For a connected graph G, let A be its adjacency
=4 matrix representation.
Consider a matrix M obtained by replacing all
Example: For the given graph, calculate the 1’s in matrix A with -1 and all 0’s in principle
total number of spanning trees possible. diagonal of matrix A with the degree of the
corresponding vertex.
Cofactor of any element of M is equal to the
number of spanning trees in G.
Graph Theory 75
Welsh-Powell algorithm:
Example: Consider the following graph, what Further, we have 4 mutually adjacent vertices
will be its chromatic number? {b, c, d, e}
\ l(G) = 4 ... (ii)
From (i) and (ii)
l(G) = 4
Connectivity:
Vertex connectivity:
In a connected graph G, the minimum
(A) 2 number of vertices whose deletion makes
graph disconnected or reduces G into a
(B) 3
trivial graph is called vertex connectivity of a
(C) 4 connected graph G. It is denoted by k(G)
(D) 5 y If G has a cut vertex, then k(G) = 1
76 Graph Theory
y The number of edges in the smallest cut Cut set:
set of G is said to be edge connectivity of It is the minimum set of edges whose removal
G. will disconnect the graph.
Example: For complete graph kn
Vertex connectivity of kn = n – 1 Matching and covering:
Edge connectivity of kn = n – 1 y Matching: If every vertex of given graph G
is incident with at the most one vertex,
i.e., deg(V) £ 1, then that subgraph is called
matching of the given graph.
In a matching, no two edges are adjacent, so y Kn has a perfect matching iff n is even.
deg(V) ≤ 1
y Maximal matching: If in any matching
M of graph G, further no more edges can Previous Years’ Questions
be included then M is said to be maximal
matching. How many perfect matching are there in
M1 and M2 are the maximal matching of G a complete graph of 6 vertices?
in the above example. [GATE CSE 2003]
y Maximum matching: For any matching M (A) 15
of Graph G, if M consists of the maximum (B) 24
number of edges. (C) 30
y Matching number: It is the number of edges (D) 60
included in a maximum matching of G. Solution: (A)
Matching number of M1 = 2
y Perfect matching: A matching of a graph Covering:
in which every vertex is matched is called Line covering:
perfect matching. A subset S(E), of graph G(V, E), will be a
Example: What is the matching number of line covering of G if all the vertices of G will
star graph with n vertices (n ³ 2) is: incident with a minimum one edge in S, i.e.,
degree of each vertex will be atleast 1.
Solution: 1
d c d c d c d c d c
a b a b a b a b a b
G C1 C2 C3 C4
Graph Theory 77
If, in any case, graph G has an isolated vertex, Maximum independent line set: The largest
line covering will not exist. maximal independent line set L of graph G
which contains a maximum number of edges,
is known as the maximum independent line
set.
y Number of edges present in the maximum
independent line set of a graph is known
G as the line independent number of G. It is
Minimal line covering: Line covering is denoted by b1
minimal if the deletion of any edge from the y Line independent number = matching
line cover is not possible. number of G1
For the graph in above example L3 is a
Minimum line covering: maximum independent line set and b1 = 3.
y The number of edges present in minimum
y For any graph G1 α 1 + β1 =| V | where a1 is
line covering is called the line covering
number of a graph G = a1 the line covering number.
The graph above example has a1 = 2.
(C1 graph is minimum line covering). Vertex covering: Let G = (V, E) be graph then
y Line covering of graph with n vertices a subset k of V is called a vertex covering of
G, if every edge of G is incident with a vertex
contains atleast n edges. in k.
2
y No minimal line covering contains a cycle.
y In a line covering, if there is no path of
length 3 or more, then C is minimal.
y In the line covering, if there are no paths
of length 3 or more, then all components
of C are star graphs. Then from those star
graphs, no edge can be deleted.
78 Graph Theory
Independent vertex set: Example: For the star graph with n
Let G = (V, E) be a graph, then the subset S vertices (n ³ 2).
of V is called an independent set if no two Solution: a2 = 1
vertices in S are adjacent. b2 = n – 1
a2 + b2 = n
Example: S3 = {a, c, e}
\ b2 = 3 Shortest path algorithms:
y For any graph a2 + b2 = |v| In order to find the shortest path between
y For any graph if S is independent set any two vertices in a graph, Dijkstra algorithm
of G then V – S = A vertex covering is used.
of G.
Graph Theory 79
Solved Examples
Solution:
VII)
I)
V)
80 Graph Theory
Grey Matter Alert!
Previous Years’ Questions
Floyd Warshell’s Algorithm
Let G = (V, G) be a weighted undirected
This algorithm can also be used to find
graph and Let T be a Minimum Spanning
the length of the shortest path between
Tree (MST) of G maintained using
all pairs of vertices in a weighted
adjacency Lists. Suppose a new weighed
connected simple graph. However, this
edge (u, v) E VxV is added to G. The worst
algorithm cannot be used to construct
case time complexity of determining if
shortest paths.
Tis still an MST of the resultant graph is:
[GATE CSE 2020]
(A) Θ(|E| + |V|)
(B) Θ(|E|.|V|)
Previous Years’ Questions
(C) Θ(|E| Log |V|)
(D) Θ(|V|)
Let G be a finite group on 84 elements. Solution: (D)
The size of a largest possible proper sub-
group of G is _______. [GATE CSE 2018]
Solution: 42
(D)
n 1 !
2
Solution: (D)
Graph Theory 81
Chapter Summary
y An undirected graph G = (V,E) consists of V, a non-empty set of vertices (or nodes) and
E, a set of edges, and every edge is associated with unordered pair of vertices.
y Types of graphs.
Simple
Multigraph
Pseudo graph
82 Graph Theory
y If G is a simple graph G ∪ G =
Kn
y Isomorphic graphs must have:
| Same number of vertices.
y Cut vertex: V3
y Bridge: e4
y Vertex Cut Set: {V3}, {V3, V1}, {V3, V2}
y Edge Cut Set: {e1, e3}, {e1, e2}, {e4}, {e1, e2, e3, e4}
Graph Theory 83