Chapter 4 (Discrete Math)
Chapter 4 (Discrete Math)
Chapter 4 (Discrete Math)
CHAPTER FOUR
Graph Theory
Example 1.1
Consider the graph G = (V , E ), where
a b
c d
4
Order and Size
Definition 1.2
The number of vertices in a graph G = (V, E) is called its order, and the
number of edges is its size. That is, the order of G is card (V) and its size
is card (E).
Example 1.2
Consider the graphs:
a a d
a
a c
G1 G2
b b
G3
c
G4
b
We see that, the order of G1 is card (V) = 1 and its size is card (E) =
0. The order of G2 is 2 and its size is 1.
The order of G3 is 3 and its size is 3. The order of G4 is 4 and its
size is 5.
5
Adjacent Vertices
Definition 1.3
Two vertices u and v are said to be adjacent (neighbours) if there exists
an edge e = {u, v} (or simply e = uv) in the graph G = (V, E).
We call u and v the end-vertices of the edge e.
Example 1.3
The vertices v1 and v2 are adjacent. Similarly, v1 and v4 are adjacent.
v2 v5
v1
v3 v4
6
Adjacent Vertices
Definition 1.4
Two edges are adjacent if they have a vertex in common.
Example 1.4
The edges e1 and e2 are adjacent edges. Similarly, e2 and e3 are adjacent
edges.
v2 v5
e1
e4 v1 e6
e2
e3
v3 v4
e5
7
Parallel edges and Loops
If there is more than one edge between the same pair of vertices,
then the edges are termed as parallel edges.
Example 1.5
In the graph G , the edges e4 and e5 are parallel edges.
e1
e4 e6
A e5 B e7 C
Example 1.6
In the graph given below, the edges e4 and e5 are loops.
e1
e2
e4 v1 v2 e5
e3
10
Simple Graph
Definition 2.1
A graph G = (V, E) that has no loop and no parallel edges is called a
simple graph.
Example 2.1
The following graph is a simple graph as it has no loop and no parallel
edges.
v2 v4
v1 v3 v5
11
Multi Graph
Definition 2.2
A graph G = (V, E) is known as a multi graph if it contains parallel edges,
(i.e. two or more edges between a pair of vertices).
Example 2.2
The graph given G given below is a multi graph as it contains parallel
edges.
D
A B C
Note that every simple graph is a multi graph, but the converse
12
Pseudo Graph
Definition 2.3
A graph G = (V, E) is known as a pseudo graph if it contains loops, and
possibly parallel edges connecting the same pair of vertices or a vertex
to itself.
Example 2.3
The graph given below is a pseudo graph.
A B
Note that every multi graph is pseudo graph but the converse
13
Directed Graph (Digraph)
14
Definition 3.1
A directed graph (or digraph) G = (V , E ) consists of a nonempty set of
vertices V and a set of directed edges E in which each edge is associated
with an ordered pair of vertices.
The directed edge associated with the ordered pair (u, v) starts at u and
ends at v.
Example 3.1
The following graph is a digraph.
v2 v5
v1
v3 v4
15
Degree of a vertex
16
Degree of a vertex
Definition 4.1
In an undirected graph, the degree of a vertex v , denoted by deg(v), is
the number of edges incident to it.
Example 4.1
Find the degree of each vertices in the following graph.
c b f
a e d
Solution: We have
17
Degree of a vertex
Note: In case of a loop, it contributes 2 to the degree of a vertex.
Example 4.2
Find the degree of vertices in the given graph.
a b
Solution:
Observe that a loop at vertex a and vertex b contributes twice
to the degree of the two vertices.
So we have,
deg(a) = 2 + 3 = 5, deg(b) = 2 + 3 = 5, and deg(c) = 2.
18
Degree of a vertex
In case of a digraph there are two degrees known as in–degree
and out–degree.
The in–degree of a vertex v in a digraph, denoted by deg+(v), is
the number of edges with v as the terminal vertex.
The out–degree of v , denoted by deg−(v), is the number of edges
with v as the initial vertex.
Example 4.3
Find the in–degree and out–degree of vertices in the graph given below.
c
a b
Solution:
The in–degrees are: deg+(a) = 3, deg+(b) = 2, deg+(c) = 1.
The out–degrees are: deg−(a) = 2, deg−(b) = 3, deg−(c) = 1.
19
Degree of a vertex
Definition 4.2
A vertex is said to be an isolated vertex if it is not adjacent to any vertex.
It follows that an isolated vertex is a vertex of degree zero.
That is, if deg(v) = 0, then v is isolated.
Example 4.4
In the graph G given below, the vertex f is an isolated vertex.
a
e b f
d c
Definition 4.3
A vertex is said to be pendant vertex if it is adjacent to exactly one other
vertex. Consequently, a pendant vertex has degree one.
Vertex e in the above graph is pendant.
20
Degree of a vertex
The Handshaking Theorem
∑ deg(vi) = 2m.
vi∈V
Example 4.5
The graph G contains 5 vertices with degrees 4, 3, 2, 2, 1. How many edges
are there in G ?
21
Special Simple Graphs
22
Complete Graphs
Definition 5.1
A complete graph is a simple graph in which each pair of vertices is
adjacent. The complete graph with n vertices is denoted Kn.
v2 v0 v0
v0 v1 v0 v1 v2 v3
K1 K2 K3 v3 K4 K5 v4
Example 5.2
The cycles C3, C4, C5, and C6 are given as follows:
v1
v1 v1
v2 v2 v1
v0 v0
v2 v0 v3 v0
v2 v3
v3 v4 v4 v5
C3 C4 C5 C6
24
Wheels
Note
We obtain a wheel Wn when we add an additional vertex to a cycle
Cn, for n ≥ 3, and connect this new vertex to each of the n vertices
in Cn by new edges.
Example 5.3
The wheels W3, W4, W5, and W6 are:
v1 v1 v2 v1
v1 v2
v3 v0 v2 v4 v0 v5 v0 v3 v6 v0
v2 v3
v3 v4 v4 v5
W3 W4 W5 W6
25
Bipartite Graphs
Definition 5.3
Bipartite graph is a graph G = (V , E ) whose vertex set V can be par-
titioned into two non–empty disjoint sets V1 and V2 such that each edge
of the graph G has one end–vertex in V1 and the other end–vertex in V2.
That is, no two vertices within the same set are adjacent.
Example 5.4
The cycle C6 is bipartite. Because its vertex set can be partitioned into
the two sets: V1 = {v0, v2, v4} and V2 = {v1, v3, v5}.
v0 v1
v2 v3
v4 v5
26
Complete Bipartite Graph
Definition 5.4
A complete bipartite graph is a bipartite graph in which every vertex of
the first set is connected to every vertex of the second set.
If there are m and n vertices in the two sets, the complete bipartite graph
is denoted by Km,n.
Example 5.5
The following three graphs are complete bipartite graph.
v
b0 b1 b0 b1 b2 b0 b1 b2
v0 v1 v2 v0 v1 v2 v0 v1 v2 v3
K3,2 K3,3 K4,3
27
Regular Graph
Definition 5.6
A simple graph is called a regular graph if every vertex of this graph has
the same degree.
A regular graph is called n–regular if every vertex in this graph has de-
gree n.
Example 5.7
The following graphs are all regular.
Note that: for each n, Cn, Qn and Kn,n are some special n–regular graphs.
28
Graphic Sequences
29
Degree Sequence
Definition 6.1
The degree sequence of a graph is the sequence of the degrees of the
vertices of the graph in decreasing order.
Example 6.1
Find the degree sequence of the following graphs.
30
Degree Sequence
Example 6.2
How many edges does a graph have if its degree sequence is 4, 3, 3, 2, 2?
Solution: The graph has 7 edges, since 4+3+3+2+2
= 14
= 7.
2 2
Definition 6.2
A sequence d1, d2, . . . , dn is called graphic sequence if it is the degree
sequence of a simple graph.
Example 6.3
The sequence 2, 2, 2 is graphic, since K3 is a graph with this degree se-
quence.
In general, the sequence n, n,..., n is graphic since Kn+1 has this
degree sequence.
31
Theorem 6.1 (Havel–Hakimi)
Subgraph
32
Subgraph and Induced Subgraph
Definition 7.1
Let G1 = (V1, E1) and G2 = (V2, E2) be two simple graphs. We say that
1 G1 is a subgraph of G2 provided that V1 ⊆ V2 and E1 ⊆ E2.
2 G1 is an induced subgraph of G2 (the subgraph induced by V1) pro-
vided that each pair of vertices in V1 are adjacent in G1 if and only
if they are adjacent in G2.
33
Subgraph and Induced Subgraph
Example 7.1
Consider the following graphs.
f f f
d e d d d
a b c a b c a b c a b c
G1 G2 G3 G4
34
Matrix Representation of Graphs
35
Adjacency Matrix
A matrix is a convenient way of representing a graph.
Two types of matrices are commonly used to represent graphs:
adjacency matrix and incidence matrix.
The adjacency matrix is based on the adjacency of vertices, and
the incidence matrix is based on incidence of vertices and edges.
Adjacency Matrix
Let G = (V , E ) be a simple undirected graph with n number of ver-
tices that are listed arbitrarily as v1, v2, . . . , vn. The adjacency matrix
for G with respect to this listing of vertices is a square matrix (zero–
one matrix of order n ×n) A = [aij] where
36
Adjacency Matrix
37
Adjacency Matrix
Adjacency matrices can also be used to represent multi graphs
and pseudo graphs.
A loop at the vertex vi is represented by aii = 1.
When multiple edges connecting a pair of vertices vi and vj
are present, the entry aij equals the number of edges that are
associated to the edge {vi, vj}.
Adjacency Matrix
Adjacency matrices can also be used to represent
digraphs. Again, when there are multiple edges from vertex vi
to vertex vj , the entry aij equals the number of edges that are
associated to the directed edge (vi, vj).
Note that the adjacency matrix for any undirected graph is symmetric. But,
for a digraph it may not be symmetric.
. 42
Incidence Matrix
44
Incidence Matrix
Incidence matrices can also be used to represent multiple edges
and loops.
Multiple edges are represented in the incidence matrix using
columns with identical entries, because these edges are incident
with the same pair of vertices.
Loops are represented using a column with exactly one entry
equal to 1.
45
Module #22 - Graphs
Incident matrix of diagraph
1
Module #22 - Graphs
Exercise
1. Find adjacency matrix
A(G) =
11/14/2023 2
Module #22 - Graphs
Graph Isomorphism
• Formal definition:
– Simple graphs G1=(V1, E1) and G2=(V2, E2)
are isomorphic iff a bijection f:V1→V2
such that a,bV1, a and b are adjacent in
G1 iff f(a) and f(b) are adjacent in G2.
– f is the “renaming” function between the two
node sets that makes the two graphs
identical.
11/14/2023 3
Module #22 - Graphs
11/14/2023 4
Module #22 - Graphs
Example 1
1 a
2 b
3 d
4 c
5
Module #22 - Graphs
Example 2
• Is the two graph Isomorphism? If isomorphic,
label the 2nd graph to show the isomorphism,
else identify difference.
b d
a b a
d c
e
e c f
f
11/14/2023 6
Module #22 - Graphs
Connectivity
❖ Basic Idea: In a Graph Reachability among vertices by
traversing the edges
Application Example:
11/14/2023 8
Module #22 - Graphs
Example
Types of Walks
• There are two types of the walk, which are described as follows:
❖ Open Walk: If the vertices at which the walk starts and ends are
different. That means for an open walk, the starting vertex and
ending vertex must be different.
❖ Closed Walk: If the vertices at which the walk starts and ends are
identical. That means for a closed walk, the starting vertex and
ending vertex must be the same.
• In a closed walk and open walk, the length of the walk must be
more than 0.
11/14/2023 10
Module #22 - Graphs
Example
• In this graph,
• Closed walk = A, B, C, D, E, C, A
• Open walk = A, B, C, D, E, C
11/14/2023 11
Module #22 - Graphs
11/14/2023 12
Module #22 - Graphs
Example
Tail = A, C, H, F, C, B
Path: F, H, C, A, B, D
Closed tail = A, C, H, F, C, B, A
11/14/2023 14
Module #22 - Graphs
Example
Cycle: A, B, D, C, A Circuit: A, B, D, C, F, H, C, A
11/14/2023 15
Module #22 - Graphs
Exercise
Find out which sequence of the vertices determines walks.
1. A, B, G, F, C, D
2. B, G, F, C, B, G, A
3. C, E, F, C
4. C, E, F, C, E
5. A, B, F, A
6. F, D, E, C, B
11/14/2023 16
Module #22 - Graphs
Solution
1. Sequence no 1 is a Trail because there is no repeated edge in the
sequence ABGFCB.
2. Sequence no 2 is a Walk because the sequence BGFCBGA
contains the repeated edges and vertices.
3. Sequence 3 is a Cycle because the sequence CEFC does not
contain any repeated vertex or edge except the starting vertex C.
4. Sequence no 4 is a Walk because the sequence CEFCE contains
the repeated edges and vertices.
5. Sequence no 5 is Not a Walk because there is no direct path to go
from B to F. That's why we can say that the sequence ABFA is
not a Walk.
6. Sequence no 6 is a Path because the sequence FDECB does not
contain any repeated edges and vertices.
11/14/2023 17
Module #22 - Graphs
Exercise
Find out which sequence of the vertices determines walks
11/14/2023 18
Module #22 - Graphs
Remarks
11/14/2023 19
Module #22 - Graphs
Important Chart:
• The above definitions can be easily remembered with the help of
following chart:
11/14/2023 20
Module #22 - Graphs
Cont. …
2. Euler circuit: is much like the Eulerian path,
but you start at one vertex, visit every vertex
exactly once, then end on your starting vertex.
• If a graph has an Euler circuit it cannot have an
Euler path and vice versa.
• If every vertex is an even degree it is an Eulerian
graph or
• A connected graph G is Eulerian if and only if G
is connected and has no vertices of odd degree.
11/14/2023 22
Module #22 - Graphs
B D
C
The original problem Equivalent multigraph
Soln: No b/c it has no tour/ path that uses each edge exactly once.
(Even if we allow the walk to start and finish in different places.)
11/14/2023 23
Module #22 - Graphs
Example
• Does the graph has Euler circuits or Euler
paths?
11/14/2023 25
Module #22 - Graphs
Example
• Does the graph has Hamiltonian
circuits or Hamiltonian paths?
11/14/2023 26
Module #22 - Graphs Summary
Module #22 - Graphs
Graph Coloring
❖ Definition: A graph has been proper colored if a color
has been assigned to each vertex in such a way that
adjacent vertices have different colors.
• A graph that can be assigned a (proper) k-coloring is k-
colorable. For Example
• 4-coloring 5-coloring
28
Module #22 - Graphs
Chromatic Number
❖ Definition: The chromatic number of a graph G is the
smallest/least number k such that G is k-colorable, and it
is denoted by χ(G).
❖ Example:
b e
a d g
c f
𝜒 𝐺 =2 𝜒(𝐺) = 3
29
Module #22 - Graphs
Exercise
❖ Find The chromatic number of the following graph
G1 G2 G3
G4 G5
30
Module #22 - Graphs
Remarks
• 𝜒 𝐺 = 1 iff G has no edges, that is, G is a null
graph.
Remarks Cont. …
• We usually show a k-coloring by writing the
numbers 1,2, ..., k next to the appropriate vertices.
• For example: diagrams (a) and (b) below illustrate a 4-
colouring and a 3-colouring of a graph G with five
vertices;
32