Unit-5 - Graph Theory
Unit-5 - Graph Theory
GTU # 3140708
Unit-5
graph theory
Unit-5
Method - 1
Basic Definitions
Basic Definitions
Graph
The elements of V are called vertices and the elements of E are called edges of
a graph G.
Note Throughout this unit we shall consider V and E are finite set.
G
# 3140708 (DM) Unit 5 – Graph theory 5
Adjacent Vertices & Incident Edge
G1 G2 G3
# 3140708 (DM) Unit 5 – Graph theory 9
Undirected Edge and Undirected Graph
𝑢 𝑒 𝑣 𝑒 = 𝑢, 𝑣
Unordered
𝑒 = 𝑣, 𝑢 pair
Any graph G which contains some A graph which has neither loop
parallel edges is called a multigraph. nor parallel edges is called a
simple graph.
A graph in which weight are assigned It can happen that two graphs
to every edge is called a weighted which look entirely different
graph. but both may represent the
same graph.
G1 G2
# 3140708 (DM) Unit 5 – Graph theory 13
Isolated Vertex and Null Graph
G
In G, 𝑣7 & 𝑣8 are isolated vertices.
# 3140708 (DM) Unit 5 – Graph theory 14
Method 1 ⇛ Example 5
Que: Draw the undirected graph G = V, E where V = {𝑎, 𝑏, 𝑐, 𝑑, 𝑒} and E =
{𝑒1 , 𝑒2 , 𝑒3 , 𝑒4 , 𝑒5 , 𝑒6 , 𝑒7 } and its incidence relations given as: 𝑒1 = 𝑎, 𝑏 , 𝑒2 =
𝑎, 𝑏 , 𝑒3 = 𝑏, 𝑐 , 𝑒4 = 𝑐, 𝑑 , 𝑒5 = 𝑏, 𝑏 , 𝑒6 = 𝑎, 𝑑 & 𝑒7 = 𝑒, 𝑑 . Discuss all
the terms.
Sol: 𝑒 𝑒7 𝑑 𝑒4 𝑐
𝑒1
𝑒6 𝑒3
𝑎 𝑏 𝑒5
𝑒2
𝑒1 Directed graph No
𝑒6 𝑒3
Undirected graph Yes
𝑎 𝑏 𝑒5 Mixed graph No
𝑒2
Multi graph Yes
e and d are adjacent vertices.
Simple graph No
e and c are not adjacent.
Weighted graph No
G has no isolated vertex.
Null graph No
e7 is incident to e and d.
e5 is a loop.
e1 and e2 are parallel edges.
# 3140708 (DM) Unit 5 – Graph theory 16
Method 1 ⇛ Example 6
< 𝑑, 𝑎 >, 𝑒3 =< 𝑏, 𝑐 >, 𝑒4 =< 𝑑, 𝑐 >, 𝑒5 =< 𝑐, 𝑓 >, 𝑒6 =, < 𝑓, 𝑓 >, 𝑒7 =< 𝑒, 𝑐
> & 𝑒8 =< 𝑐, 𝑒 >. Discuss all the term.
Sol:
𝑏 𝑒3 𝑐 𝑒5 𝑓 𝑒6
𝑔
𝑒1 𝑒4 𝑒8
𝑒7
𝑎 𝑒2 𝑑 𝑒
𝑒1 𝑒4 𝑒8
𝑔
Directed graph Yes
𝑒7 Undirected graph No
𝑎 𝑒2 𝑑 𝑒 Mixed graph No
Multi graph No
c and f are adjacent vertices.
Simple graph No
b and f are not adjacent.
Weighted graph No
g is isolated vertex.
Null graph No
e7 is incident to c and e.
e6 is loop.
There are no parallel edges.
# 3140708 (DM) Unit 5 – Graph theory 18
Method - 2
Properties of Graphs
d 𝑣1 = 4 d 𝑣4 = 6 d 𝑣7 = 0
d 𝑣2 = 3 d 𝑣5 = 2 d 𝑣8 = 0
d 𝑣3 = 1 d 𝑣6 = 1 d 𝑣9 = 3
Statement Any undirected graph G with ‘𝑛’ vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛 and ‘𝑒’ edges,
𝑛
d 𝑣𝑖 = d 𝑣1 + d 𝑣2 + ⋯ + d 𝑣𝑛 = 2𝑒.
𝑖=1
Proof Continue
i.e. d 𝑣𝑖 = 2𝑒 .
𝑖=1
d 𝑣𝑖 = d 𝑣1 + d 𝑣2 + d 𝑣3 + d 𝑣4
𝑖=1
+ d 𝑣5 + d 𝑣6 + d 𝑣7 + d 𝑣8 + d 𝑣9
= 4 +3 +1 +6+2 +1+0 +0 +3
= 20 = 2 10 = 2𝑒.
We divide V into two sets say U and W. Where, U is the set of even
vertices and W is the set of odd vertices.
Therefore, d 𝑣 + d 𝑣 = 2𝑒.
𝑣∈U 𝑣∈W
# 3140708 (DM) Unit 5 – Graph theory 27
𝟐𝐧𝐝 Theorem of Graph Theory
Proof Continue Example
⇒ d 𝑣 = 2𝑒 − d 𝑣
𝑣∈W 𝑣∈U
= even − even
⇒ d 𝑣 is an even number.
𝑣∈W
Let G be a directed graph then for any vertex 𝑣 ∈ G, the number of edges which
have 𝑣 as their terminal vertex is called the indegree of the vertex 𝑣.
OR
In a directed graph G, the number of edges directed towards vertex 𝑣 is called
indegree of the vertex 𝑣.
# 3140708 (DM) Unit 5 – Graph theory 29
Total Degree of a Vertex for a Directed Graph
Let G be a directed graph then the sum of indegree and outdegree of vertex 𝑢
is called the total degree of the vertex 𝑢.
The outdegree of the vertex 𝑢 is denoted by d+ 𝑢 .
The indegree of the vertex 𝑢 is denoted by d− 𝑢 .
The total degree of the vertex 𝑢 is denoted by d 𝑢 .
i.e. d u = d+ u + d− u .
Example Find outdegree, indegree and total degree of all the vertices of following
graph G.
Solution
OR
The sum of indegrees of all the vertices of a simple digraph is equal to sum of
outdegrees of all its vertices which is equal to the number of edges of the graph.
= 𝑒 + 𝑒 = 2𝑒.
Example Verify degree sum formula for the following directed graph G.
Solution In G, the number of vertices is 𝑛 = 4
and the number of edges is 𝑒 = 6.
4 4
d+ 𝑣𝑖 = 6 = 𝑒, d− 𝑣𝑖 = 6 = 𝑒 & d 𝑣𝑖 = 12 = 2𝑒.
4
G
𝑖=1 𝑖=1 𝑖=1
A graph in which all the vertices having same degree is called a regular graph.
If for every vertex 𝑣 ∈ V G if d 𝑣 = 𝑘 for some 𝑘 ∈ ℕ then G is called a
𝒌 −regular graph.
𝟎 −regular 𝟏 −regular
𝟐 −regular graphs
# 3140708 (DM) Unit 5 – Graph theory 36
Regular Graph
Petersen Graph
𝟑 −regular graphs
A simple graph G in which there exists an edge between every pair of vertices is
called a complete graph.
A complete graph with n vertices is denoted by K n .
The complete graph with n vertices K n is n − 1 regular.
K1 K2 K3
𝟎 −regular 𝟏 −regular 𝟐 −regular
# 3140708 (DM) Unit 5 – Graph theory 38
Complete Graph
K4 K5 K6
𝟑 −regular 𝟒 −regular 𝟓 −regular
𝑒4
K5
# 3140708 (DM) Unit 5 – Graph theory 40
Subgraph
Let G and H be two graphs. Then H is said to be a subgraph of G if V H ⊆ V G
and E H ⊆ E G . Here G is called a super graph of H.
𝑎 𝑎
𝑒 𝑏 𝑒 𝑏
𝑑 𝑐 𝑑 𝑐
G G −{a}
# 3140708 (DM) Unit 5 – Graph theory 42
Edge Deleted Subgraph
The graph obtain by deletion of an edge 𝑒 from a given graph G is called an
edge deleted subgraph of G. It is denoted by G − 𝑒 .
𝑎 𝑎
𝑒1 𝑒1
𝑒 𝑏 𝑒 𝑏
𝑑 𝑐 𝑑 𝑐
G G −{e1 }
# 3140708 (DM) Unit 5 – Graph theory 43
Example on Vertex Deleted Subgraph and Edge Deleted Subgraph
Example Find subgraphs from given graph G by deleting a vertex 𝑣1 and an edge 𝑒4 .
Solution
𝑣1 v1 𝑣1
𝑒1 𝑒7 𝑒6 e1 e7 𝑒6 𝑒1 𝑒7 𝑒6
𝑒8 𝑒8 𝑒8
𝑣2 𝑣2 𝑣2
𝑣5 𝑣5 𝑣5
𝑒2 𝑒5 𝑒2 𝑒5 𝑒2 𝑒5
𝑒3 𝑒3 𝑒3
𝑣3 𝑒4 𝑣4 𝑣3 𝑒4 𝑣4 𝑣3 e4 𝑣4
G G − {v1 } G − {e4 }
e b e b e b
d c d c d c
G S ഥ
S
# 3140708 (DM) Unit 5 – Graph theory 45
Converse(Reversal/Directional Dual) of a Directed Graph
෩ =< V, ෩
The converse of a directed graph G =< V, E > is a directed graph G E>
in which the relation ෩
E is the converse of the relation E.
෩ is obtained from G by reversing the directions of all edges in G.
The diagram G
v2 𝐯𝟐
v1 v3 𝐯𝟏 𝐯𝟑
v4 𝐯𝟒
G ෩
G
# 3140708 (DM) Unit 5 – Graph theory 46
Isomorphic Graph Bijection means one-one & onto function
A graph G1 = V1 , E1 is said to be isomorphic to the graph G2 = V2 , E2
if there exists a bijection between the set of vertices V1 and V2 and a bijection
between the set of edges E1 and E2 such that 𝑒 is an edge with end vertices 𝑢
and 𝑣 in G1 then the corresponding edge 𝑒 ′ has end vertices 𝑢′ and 𝑣 ′ in G2
which correspond to 𝑢 and 𝑣 respectively. If such pair of bijection exist then
it is called a graph isomorphism and it is denoted by G1 ≅ G2 .
According to the definition of isomorphism we note that any two vertices in one
graph which are joined by an edge must have the corresponding vertices in the
other graph also joined by an edge and hence a bijection is exists between the
edges as well.
# 3140708 (DM) Unit 5 – Graph theory 47
Example of Isomorphic Graph
1 𝑎 Vertex Edge
5 Mapping Mapping
𝑒 𝑏 1→𝑎 1, 3 → 𝑎, 𝑏
2
3→𝑏 3, 5 → 𝑏, 𝑐
5→𝑐 5, 2 → 𝑐, 𝑑
4 3 2, 4 → 𝑑, 𝑒
𝑐 2→𝑑
G1 𝑑
G2 4→𝑒 4, 1 → 𝑒, 𝑎
Here vertex mapping and edge mapping both are one-one and onto (bijective).
Hence, there exists a bijection between set of vertices and set of edges.
⇒ G1 and G2 are isomorphic. i.e. G1 ≅ G2 .
𝟏 𝐯𝟏 Vertex Edge
Mapping Mapping
1 → 𝑣1 < 1, 2 > → < 𝑣1 , 𝑣2 >
𝟑 2 → 𝑣2 < 2, 3 > → < 𝑣2 , 𝑣3 >
𝐯𝟑
𝟐 𝐯𝟐
3 → 𝑣3 < 𝟑, 𝟏 > ↛ < 𝒗𝟑 , 𝒗𝟏 >
G1 G2
Here G1 and G2 both has same number of vertices and edges but G1 is not
isomorphic to G2 . i.e. G1 ≇ G2 . Because < 3, 1 > ↛ < 𝑣3 , 𝑣1 >.
Here vertex mapping and edge mapping both are one-one and onto (bijective).
Hence, there exists a bijection between set of vertices and set of edges.
⇒ G1 and G2 are isomorphic. i.e. G1 ≅ G2 .
G H
# 3140708 (DM) Unit 5 – Graph theory 51
Method 2 ⇛ Example 7 (a)
Question Check whether the following pair of graphs G and H are isomorphic or not
with description.
2 𝒆𝟒 3 𝑏 𝑑 𝑓
𝒆𝟏 𝒆𝟓
𝒆𝟔
𝒆𝟐
1 4 𝒆′𝟐 𝒆′𝟓 𝒆′𝟖
𝒆′𝟗
𝒆′𝟏
𝒆𝟕 𝒆′𝟑 𝒆′𝟔
𝒆𝟑 𝒆′𝟒 𝒆′𝟕
𝒆𝟖
𝑎 𝑐 𝑒
𝒆𝟗
6 5
G H
Solution one digraph with no edge one digraph with one edge
Path Connectedness
Cycle Weakly Connected Digraph
Reachability Unilaterally Connected Digraph
Reachable Set Strongly Connected Digraph
Node Base
Path of a Graph
Let G =< V, E > be a digraph. Consider a sequence of edges of G such that
terminal vertex of any edge in the sequence is the initial vertex of next edge.
Such a sequence is called a path of the given graph G.
A path which start and end in the same vertex is called a cycle(circuit).
2 Cycle of a given digraph
1
C1 = (< 1,1 >)
C2 = (< 1,2 >, < 2,1 >)
C3 = (< 1,2 >, < 2,3 >, < 3,1 >)
4 3
C4 = (< 1,4 >, < 4,3 >, < 3,1 >)
C5 = (< 1,4 >, < 4,3 >, < 3,2 >, < 2,1 >)
# 3140708 (DM) Unit 5 – Graph theory 61
Simple Cycle, Elementary Cycle and Acyclic Graph
A cycle is called a simple cycle if its A cycle is called an elementary cycle
path is simple path. i.e., no edge in if it does not traverse through any
the cycle appears more than once in vertex more than once.
the path.
In previous slide all cycles 𝐂𝟏 , 𝐂𝟐 , 𝐂𝟑 , 𝐂𝟒 & 𝐂𝟓 are simple and elementary.
In cycle the initial vertex appears at least twice even if it is an elementary cycle.
Any path which is not elementary contains a cycle traversing through those
vertices which appear more than once in the path.
A digraph which does not have any cycle is called an acyclic graph.
𝑣1 𝑣4 𝑣5 𝑣1 𝑣4 𝑣5 𝑣1 𝑣4 𝑣5
𝑣2 𝑣3 𝑣2 𝑣3 𝑣2 𝑣3
G 𝐆 −< 𝒗𝟏 , 𝒗𝟐 > 𝐆 −< 𝒗𝟒 , 𝒗𝟏 >
𝑣2 𝑣3
The length of a geodesic from the vertex 𝑢 to the vertex 𝑣 is called the distance
and it is denoted by 𝐝 < 𝒖, 𝒗 >.
𝑣2 𝑣3
Note If 𝑣 is not reachable form 𝑢 then it is customary to write d < 𝑢, 𝑣 > = ∞.
(It means not defined)
If 𝑣 is reachable from 𝑢 and 𝑢 is reachable from 𝑣 then d < 𝑢, 𝑣 > is not
necessarily equal to d < 𝑣, 𝑢 >.
# 3140708 (DM) Unit 5 – Graph theory 68
Reachable Set
The set of vertices which are reachable from a given vertex 𝑣 is said to be the
the reachable set of 𝐯. The reachable set of 𝑣 is denoted by R(𝑣).
For any subset S ⊆ V, the reachable set of 𝐒 R(S) is the set of vertices which
are reachable from any vertex of S.
R 𝑣1 = 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 , 𝑣5 , 𝑣6
R 𝑣1 = R 𝑣2 = R 𝑣3 = R 𝑣4 = R 𝑣5
R 𝑣6 = 𝑣6
R 𝑣7 = 𝑣6 , 𝑣7 R 𝑣9 = 𝑣9
R 𝑣8 = 𝑣6 , 𝑣7 , 𝑣8 R 𝑣10 = 𝑣10
Question Find the reachable set for all the vertices in the following digraph.
Solution
𝒗𝟏 𝒗𝟒
R 𝑣1 = {𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 }
R 𝑣2 = {𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 }
R 𝑣3 = 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4
𝒗𝟐 𝒗𝟑
R 𝑣4 = {𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 }
𝒗𝟏 𝒗𝟐 𝒗𝟓 𝒗𝟔 𝒗𝟗
R 𝑣1 = 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 , 𝑣5 , 𝑣6
R 𝑣8 = 𝑣6 , 𝑣7 , 𝑣8
R 𝑣9 = 𝑣9
𝒗𝟒 𝒗𝟑 𝒗𝟕 𝒗𝟖 𝒗𝟏𝟎 R 𝑣10 = 𝑣10
R 𝑣1 , 𝑣8 , 𝑣9 , 𝑣10 = 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 , 𝑣5 , 𝑣6 , 𝑣7 , 𝑣8 , 𝑣9 , 𝑣10 = V
Hence, 𝑣1 , 𝑣8 , 𝑣9 , 𝑣10 is a node base.
# 3140708 (DM) Unit 5 – Graph theory 71
Method 3 ⇛ Example 7
Question Find a node base for both digraphs as given below.
𝑣1 𝑣4
Solution 𝑣5
𝑣1 𝑣4
𝑣2 𝑣3
G2
𝑣2 𝑣3 R v1 = 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 , 𝑣5 = V
G1
⇒ {𝑣1 } is a node base of G2 .
R v1 = 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 = V
Similarly, we observe {𝑣2 }, {𝑣3 } & {𝑣4 } are
⇒ {𝑣1 } is a node base of G1 .
also node base of G2 .
# 3140708 (DM) Unit 5 – Graph theory 72
Connectedness
An undirected graph is called connected if for any two vertices from the graph
they are reachable from one another.
G1 G2
Connected Graph Disconnected Graph
# 3140708 (DM) Unit 5 – Graph theory 73
Weakly Connected Graph and Unilaterally Connected Digraph
4 5 6
S2 S3 S4
2 1
5 2 1
G S1
# 3140708 (DM) Unit 5 – Graph theory 76
Unilateral Component of a Digraph
For a digraph a maximal unilaterally connected subgraph is called a unilateral
component.
Note Maximal unilaterally connected subgraph of G it means a subgraph S of G
which is unilaterally connected but no super graph of S which is unilaterally
connected. There are two unilateral components of 𝐆 which are
3 4 6
3 4
S2
2 1
5 2 1
G S1
5
2 1 2 1
5 5
G G
# 3140708 (DM) Unit 5 – Graph theory 78
Method 3 ⇛ Example 8
Question Determine whether the digraph G1 is strongly, weakly and unilaterally
connected.
Solution G1 is not strongly connected because not existing path from 𝑣2 to 𝑣1 .
𝑣1 𝑣4
Path from 𝑣1 → 𝑣2 , 𝑣1 → 𝑣3 & 𝑣1 → 𝑣4 is exist in G1 .
Path from 𝑣2 → 𝑣3 & 𝑣2 → 𝑣4 is exist in G1 .
Path from 𝑣3 → 𝑣4 is exist in G1 .
⇒ G1 is unilaterally connected implies weakly connected.
𝑣2 𝑣3
G1
We shall show how a simple digraph can be used to represent the resource
allocation status of an operating system.
It may happen that requests for resources are in conflict. For example, program A
may have control of resource r1 and require resource r2 but program B has
control of resource r2 and requires resource r1 . In such a case the computer
system is said to be in a state known as deadlock and the conflicting requests
must be resolved.
A directed graph can be used to model resource requests and assist in the
detection and correction of deadlocks.
It is assumed that all resource requests of a program must be satisfied before
that program can complete execution. If any requested resources are unavailable
at the time of the request the program will assume control of the resources
which are available but must wait for the unavailable resources.
# 3140708 (DM) Unit 5 – Graph theory 82
Application of Simple Digraph to Represent Resource Allocation Status of an Operating System
𝑟1
p1 has resource r4 and requires r1 .
𝑝2 𝑝1
p2 has resource r1 and requires r2 and r3 .
𝑟2 𝑝4 𝑝2 𝑟4 p3 has resource r2 and requires r3 .
Adjacency Matrix
Path(Reachability) Matrix
Warshall’s Algorithm to Produce a Path Matrix
Introduction
A diagrammatic representation of a graph has limited usefulness. Furthermore,
such a representation is only possible when the number of vertices and edges is
reasonably small.
Well known operations of matrix algebra can be used to calculate paths, cycles
and other characteristics of a graph.
.
.
.
𝑣1 𝑎11 𝑎12 𝑎13 𝑎1𝑛
.
.
.
𝑣2 𝑎21 𝑎22 𝑎23 𝑎2𝑛
.
.
.
𝑣3 𝑎31 𝑎32 𝑎33 𝑎3𝑛
.
.
.
A = 𝑎𝑖𝑗 𝑛×𝑛
= . . . . .
. . . . .
. . . . .
𝑣𝑛 𝑎𝑛1 𝑎𝑛2 𝑎𝑛3 𝑎𝑛𝑛
.
.
.
𝑛×𝑛
Solution 𝑣1 𝑣2
𝑣1 𝑣2 𝑣3 𝑣4
𝑣1 𝑎011 𝑎112 𝑎0
13 𝑎014
𝑣2 𝑎021 𝑎022 𝑎123 𝑎124
A = 𝑎𝑖𝑗 4×4
=
𝑣3 𝑎131 𝑎132 𝑎033 𝑎134 𝑣4 𝑣3
𝑣1 𝑣2 𝑣3 𝑣4
𝑣1 𝑣2 Vertex Outdegree Indegree
𝑣1 0 1 0 0
𝑣1 d+ 𝑣1 = 1 d− 𝑣1 =2
𝑣2 0 0 1 1
A= 𝑣2 d+ 𝑣2 = 2 d− 𝑣2 =2
𝑣3 1 1 0 1
𝑣3 d+ 𝑣3 = 3 d− 𝑣3 =1
𝑣4 𝑣3 𝑣4 1 0 0 0
𝑣4 d+ 𝑣4 = 1 d− 𝑣4 =2
However, any one of the adjacency matrices of G can be obtained from another
adjacency matrix of the same graph by interchanging some of the rows and the
corresponding column of the matrix. But the digraphs of both the matrix are
isomorphic.
For a null graph which consists of only n vertices but no edges, the adjacency
matrix is a null matrix.
# 3140708 (DM) Unit 5 – Graph theory 92
Remarks on Adjacency Matrix
If there are loops at each vertex but no other edges in the graph then the
adjacency matrix is the identity matrix.
If a digraph is reflexive then the diagonal elements of adjacency matrix are 1’s.
The adjacency matrix for symmetric digraph is also symmetric. i.e., aij = aji
for all i and j.
Let G = < V, E > be a simple digraph and A be the adjacency matrix of G. The
element in the ith row and jth column of the matrix A𝑛 is equal to the number of
paths of length 𝑛 from the ith vertex to the jth vertex.
0 1 0 0 0 0 1 1
0 0 1 1 2 1 0 1
Here, A = ⇒A = 2
1 1 0 1 1 1 1 1
1 0 0 0 0 1 0 0
2 1 0 1 1 2 1 1
3 1 2 1 1 4 2 2 2 3
⇒A = ⇒A =
2 2 1 2 3 3 2 3
0 0 1 1 2 1 0 1
# 3140708 (DM) Unit 5 – Graph theory 99
Solution Continue
P1 𝑖, 𝑗 = 1 if there is a simple path from 𝑣𝑖 to 𝑣𝑗 which does not use any vertex
except possibly 𝑣1 .
There is a simple path from 𝑣i to 𝑣j which does not use any other vertices
except possibly 𝑣1 , 𝑣2 , … , 𝑣𝑘−1 ; hence P𝑘−1 𝑖, 𝑗 = 1.
There is a simple path from 𝑣i to 𝑣k and a simple path from 𝑣𝑘 to 𝑣𝑗 where each
simple path does not use any other vertices except possibly 𝑣1 , 𝑣2 , … , 𝑣𝑘−1 .
Hence P𝑘−1 𝑖, 𝑘 = 1 & P𝑘−1 𝑘, 𝑗 = 1.
Here, we use the logical operator ∨(OR) and ∧(AND). In other words we can
obtain each entry in the matrix P𝑘 by only three entries in the matrix P𝑘−1 .
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣5
𝑣2
𝑣1 𝑎011 𝑎112 𝑎0
13 14 𝑎15
𝑎0 0
𝑣2 𝑎021 𝑎022 𝑎023 𝑎124 𝑎025
P0 = A = 𝑎𝑖𝑗 = 𝑣4 𝑣3
5×5 𝑣3 𝑎034 𝑎035
𝑎131 𝑎032 𝑎033
𝑣4 𝑎041 𝑎042 𝑎043 𝑎044 𝑎145
𝑣5 𝑎041 𝑎142 𝑎043 𝑎044 𝑎045
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣5
𝑣2
𝑣1 𝑣1 1 0
0 1 0 0 0 0 1 0 0
𝑣2 0 0 1 0 𝑣2 0 0 1 0
0 0 𝑣4 𝑣3
P1 = 𝑣3 1 1 0 0 0 ⇒ P2 = 𝑣3 1 1 0 1 0
0
𝑣4 0 0 0 0 1 𝑣4 0 0 0 0 1
𝑣5 0 1 0 0 0 𝑣5 0 1 0 1 0
0
Intermediate 𝑣1 , 𝑣2
# 3140708 (DM) Unit 5 – Graph theory 109
Method 4 ⇛ Example 5 (Continue)
Question Apply Warshall’s algorithm to produce a path matrix for the given graph.
Solution Continue P3 𝑖, 𝑗 = P2 𝑖, 𝑗 ∨ P2 𝑖, 3 ∧ P2 3, 𝑗 𝑣1
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣5
𝑣2
𝑣1 𝑣1
0 1 0 1 0 0 1 0 1 0
𝑣2 0 0 1 0 𝑣2 0 0 1 0
0 0 𝑣4 𝑣3
P2 = 𝑣3 1 1 0 1 0 ⇒ P3 = 𝑣3 1 1 0 1 0
𝑣4 0 0 0 0 1 𝑣4 0 0 0 0 1
𝑣5 0 1 0 1 0 𝑣5 0 1 0 1 0
Intermediate 𝑣1 , 𝑣2 , 𝑣3
# 3140708 (DM) Unit 5 – Graph theory 110
Method 4 ⇛ Example 5 (Continue)
Question Apply Warshall’s algorithm to produce a path matrix for the given graph.
Solution Continue P4 𝑖, 𝑗 = P3 𝑖, 𝑗 ∨ P3 𝑖, 4 ∧ P3 4, 𝑗 𝑣1
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣5
𝑣2
𝑣1 𝑣1
0 1 0 1 0 0 1 0 1
1 0
𝑣2 0 0 1 0 𝑣2 0 0 1
1 0
0 0 𝑣4 𝑣3
P3 = 𝑣3 1 1 0 1 0 ⇒ P4 = 𝑣3 1 1 0 1
1 0
𝑣4 0 0 0 0 1 𝑣4 0 0 0 0 1
𝑣5 0 1 0 1 0 𝑣5 0 1 0 1
1 0
Intermediate 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4
# 3140708 (DM) Unit 5 – Graph theory 111
Method 4 ⇛ Example 5 (Continue)
Question Apply Warshall’s algorithm to produce a path matrix for the given graph.
Solution Continue P5 𝑖, 𝑗 = P4 𝑖, 𝑗 ∨ P4 𝑖, 5 ∧ P4 5, 𝑗 𝑣1
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣5
𝑣2
𝑣1 𝑣1
0 1 0 1 1 0 1 0 1 1
𝑣2 0 0 1 1 𝑣2 0 1
0 0 1 1
0 𝑣4 𝑣3
P4 = 𝑣3 1 1 0 1 1 ⇒ P5 = 𝑣3 1 1 0 1 1
𝑣4 0 0 0 0 1 𝑣4 0 1
0 0 1 1
0
𝑣5 0 1 0 1 1 𝑣5 0 1 0 1 1
Intermediate 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 , 𝑣5
# 3140708 (DM) Unit 5 – Graph theory 112
Method 4 ⇛ Example 5 (Continue)
Question Apply Warshall’s algorithm to produce a path matrix for the given graph.
Solution Continue 𝑣1
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣5
𝑣1 𝑣2
0 1 0 1 1
𝑣2 0 1 0 1 1
Hence, P5 = P = 𝑣3 1 1 0 1 1 𝑣4 𝑣3
𝑣4 0 1 0 1 1
𝑣5 0 1 0 1 1
𝑣4 𝑣3
𝒗𝟏 𝒗𝟐 𝒗𝟑 𝒗𝟒 𝒗𝟏 𝒗𝟐 𝒗𝟑 𝒗𝟒
Sol:
𝒗𝟏 0 1 0 0 𝒗𝟏 0 0 1 1
𝒗𝟐 0 0 1 1 2 𝒗𝟐 2 1 0 1
Adjacency matrix A = ⇒A =
𝒗𝟑 1 1 0 1 𝒗𝟑 1 1 1 1
𝒗𝟒 1 0 0 0 𝒗𝟒 0 1 0 0
# 3140708 (DM) Unit 5 – Graph theory 114
Method 4 ⇛ Example 2 (Continue)
Que: Find A and 𝐴2 without a matrix multiplication for the given digraph. Where, A
is an adjacency matrix.
𝑣2 𝑣1
A ⇒ reachable by using 1 edge
A2 ⇒ reacable by using 2 edges
𝑣3 𝑣4
𝒗𝟏 𝒗𝟐 𝒗𝟑 𝒗𝟒 𝒗𝟏 𝒗𝟐 𝒗𝟑 𝒗𝟒
Sol:
𝒗𝟏 0 0 0 1 𝒗𝟏 0 0 1 0
𝒗𝟐 1 0 1 1 2 𝒗𝟐 1 0 1 2
Adjacency matrix A = ⇒A =
𝒗𝟑
𝒗𝟑 1 0 0 1 0 0 1 1
𝒗𝟒 0 0 1 0 𝒗𝟒 1 0 0 1
# 3140708 (DM) Unit 5 – Graph theory 115
Method - 5
Properties of Tree & it’s Representations
Tree Binary Tree
Forest m-ary Tree
Leaf, Branch and Level Descendent and Son
Path Representation of Vertices in a Binary
Different Representation of a Tree Tree
Convert any m-ary Tree to a Binary Tree
Tree
A graph which does not have any cycle is called an acyclic graph.
A tree is a connected acyclic graph.
tree is acyclic.
Level 𝟎
𝒗𝟎
Undirected tree
Method B Parenthesis
(𝑣0(𝑣1(𝑣2 )(𝑣3(𝑣4 )(𝑣5 )))(𝑣6(𝑣7(𝑣8 ))(𝑣9 )(𝑣10 )))
# 3140708 (DM) Unit 5 – Graph theory 121
Binary Tree and a Complete(full) Binary Tree
In a directed tree the outdegree of every vertex is less than or equal to 2 then
the tree is called a binary tree.
If the outdegree of every vertex is exactly equal to 0 OR 2 then the tree is called
a full(complete) binary tree.
0 1 0 1
0 1 0 1
01 10 11 00 10 11
The above figures shows distinct positional trees but they are not distinct
ordered trees.
In a positional binary tree, every vertex is uniquely represented by a string over
the numbers 0, 1 , the root being represented by an empty string.
𝟏. Delete all the branches originating in every vertex except the left most branch.
𝟐. Draw edges from a vertex to the vertex on the right, if any, which is situated at
the same level.
𝟑. Choose its left and right sons as below.
(𝒂) The left son is the vertex which is immediately below the given vertex.
(𝒃) The right son is the vertex to the immediate right of the given vertex on the
same horizontal line.
2 5
3 4 Stage-1
Given Tree
6 7 8 9 10 11
6 3
4
7 8
5 Stage-1
F B E
C D
G C D F
H
G
Binary Tree
H
Pre-order traversal B E
Process the root vertex.
F
Traverse the left sub-tree in pre-order. C D
Traverse the right sub-tree in pre-order. G
H
Pre-order 𝐀 𝐁 𝐂 𝐃 𝐄 𝐅 𝐆 𝐇
# 3140708 (DM) Unit 5 – Graph theory 133
In-order Traversal
In-order traversal A
In-order 𝐂 𝐁 𝐃 𝐀 𝐄 𝐆 𝐇 𝐅
Post-order 𝐂 𝐃 𝐁 𝐇 𝐆 𝐅 𝐄 𝐀
⇒ d 𝑣1 + d 𝑣2 + d 𝑣3 + d 𝑣4 + d 𝑣5 = 2𝑒
⇒ 2 + 2 + 2 + 2 + 2 = 2𝑒
⇒ 2𝑒 = 10
⇒𝑒=5
Hence, G has 5 number of edges.
⇒ d 𝑣1 + d 𝑣2 + d 𝑣3 + d 𝑣4 + d 𝑣5 = even
⇒ 3 + 3 + 3 + 3 + 3 = even
⇒ 15 = even
Which is not possible.
So, 3 −regular graph with 5 vertices is not possible.
# 3140708 (DM) Unit 5 – Graph theory 140
Discrete Mathematics (DM)
GTU # 3140708
THANK
YOU