0% found this document useful (0 votes)
2 views141 pages

Unit-5 - Graph Theory

This document covers the fundamentals of graph theory, including definitions of graphs, vertices, edges, and various types of graphs such as directed, undirected, and weighted graphs. It explains concepts like adjacent vertices, loops, parallel edges, and the degree of a vertex, along with examples to illustrate these concepts. Additionally, it introduces properties of graphs and the handshaking theorem, which relates the degrees of vertices to the number of edges in a graph.

Uploaded by

kar424353
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)
2 views141 pages

Unit-5 - Graph Theory

This document covers the fundamentals of graph theory, including definitions of graphs, vertices, edges, and various types of graphs such as directed, undirected, and weighted graphs. It explains concepts like adjacent vertices, loops, parallel edges, and the degree of a vertex, along with examples to illustrate these concepts. Additionally, it introduces properties of graphs and the handshaking theorem, which relates the degrees of vertices to the number of edges in a graph.

Uploaded by

kar424353
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/ 141

Discrete Mathematics (DM)

GTU # 3140708

Unit-5
graph theory
Unit-5
Method - 1
Basic Definitions

 Basic Definitions
Graph

A graph G = ( V, E, 𝜙 ) consists of a nonempty set V(The set of vertices),


E(The set of edges) and a mapping 𝜙 from E to V × V.

V = V G = 𝑣1 , 𝑣2 , 𝑣3 , … = The set of vertices(nods/points/dots/junctions).

E = E G = 𝑒1 , 𝑒2 , 𝑒3 , … = The set of edges(branch/line/arc).

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.

# 3140708 (DM)  Unit 5 – Graph theory 4


Graph
𝑣2 𝑣7 V = 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 , 𝑣5 , 𝑣6 , 𝑣7 , 𝑣8 , 𝑣9
𝑒5 𝑣8
𝑒2 E = 𝑒1 , 𝑒2 , 𝑒3 , 𝑒4 , 𝑒5 , 𝑒6 , 𝑒7 , 𝑒8 , 𝑒9 , 𝑒10
𝑣3
𝑒1 𝑣1
𝑒3 𝑣5 𝑒1 = 𝑣1 , 𝑣1 𝑒6 = 𝑣4 , 𝑣5
𝑒6
𝑒7 𝑒2 = 𝑣1 , 𝑣2 𝑒7 = 𝑣5 , 𝑣6
𝑒4
𝑣4 𝑒8 𝑣6 𝑒3 = 𝑣2 , 𝑣4 𝑒8 = 𝑣4 , 𝑣9
𝑒9 𝑒4 = 𝑣1 , 𝑣4 𝑒9 = 𝑣4 , 𝑣9
𝑒10 𝑣9 𝑒5 = 𝑣2 , 𝑣3 𝑒10 = 𝑣4 , 𝑣9

G
# 3140708 (DM)  Unit 5 – Graph theory 5
Adjacent Vertices & Incident Edge

Any edge e can be made by one OR two vertices.


𝑢 𝑒 𝑣
𝑒 𝑢
𝑒 = 𝑢, 𝑣
𝑒 = 𝑢, 𝑢 unordered pair
𝑒 = 𝑣, 𝑢
If two vertices 𝑢 and 𝑣 are joined by an edge 𝑒 then 𝑢 and 𝑣 are said to be
adjacent vertices.

An edge 𝑒 ∈ E which joins the vertices 𝑢 and 𝑣 is said to be incident to the


vertices 𝑢 and 𝑣.

# 3140708 (DM)  Unit 5 – Graph theory 6


Loop(Sling) & Parallel Edges(Multiple Edges)

An edge 𝑒 of a graph G that joins a If two vertices of a graph are joined by


vertex 𝑢 to itself is called a loop. more than one edge then these edges
i.e., A loop is an edge 𝑒 = 𝑢, 𝑢 . are called parallel edges.
𝑒 𝑢 𝑒1
𝑒 = 𝑢, 𝑢 𝑒2
𝑢 𝑒3 𝑣

Here 𝑒 is a self loop. Here 𝑒1 , 𝑒2 and 𝑒3 are parallel edges.

# 3140708 (DM)  Unit 5 – Graph theory 7


Directed Edge, Initial Vertex and Terminal Vertex

In a graph G an edge 𝑒 which is associated with an ordered pair of vertices 𝑢 to


𝑣 is called directed edge of a graph G.

Let G = V, E be a graph and let e ∈ E be a directed edge associated with the


order pair < u, v > of vertices 𝑢 and 𝑣 then the edge 𝑒 is said to be initiating
(originating) in the vertex 𝑢 and terminating(ending) in the vertex 𝑣.

The vertex 𝑢 is called initial vertex of edge 𝑒. 𝑢 𝑒 𝑣


The vertex 𝑣 is called terminal vertex of edge 𝑒.
𝑒 =< 𝑢, 𝑣 >
ordered
𝑒 ≠< 𝑣, 𝑢 > pair

# 3140708 (DM)  Unit 5 – Graph theory 8


Directed Graph(Digraph)

A graph G in which every edge is directed is called a directed graph.

G1 G2 G3
# 3140708 (DM)  Unit 5 – Graph theory 9
Undirected Edge and Undirected Graph

In a graph G an edge 𝑒 which is associated with an unordered pair 𝑢, 𝑣 of


vertices 𝑢 and 𝑣 is called undirected edge of a graph G.

𝑢 𝑒 𝑣 𝑒 = 𝑢, 𝑣
Unordered
𝑒 = 𝑣, 𝑢 pair

A graph in which every edge is undirected


is called an undirected graph.

# 3140708 (DM)  Unit 5 – Graph theory 10


Mixed Graph and Distinct Edges

If some edges of a graph G are The two possible edges between a


directed and some edges are pair of vertices which are opposite
undirected then G is said to be in direction which are known as
a mixed graph. distinct edges.

# 3140708 (DM)  Unit 5 – Graph theory 11


Multi Graph and Simple Graph

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.

# 3140708 (DM)  Unit 5 – Graph theory 12


Weighted 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

In a graph a vertex which is not A graph which contains only isolated


adjacent to any other vertex is vertices is called a null graph.
called an isolated vertex.

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

# 3140708 (DM)  Unit 5 – Graph theory 15


Method 1 ⇛ Example 5(continue)
𝑒 𝑒7 𝑑 𝑒4 𝑐  All edges of G are undirected.

𝑒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

Que: Draw the directed graph G = V, E where V = {𝑎, 𝑏, 𝑐, 𝑑, 𝑒, 𝑓, 𝑔} and E


= {e1 , e2 , e3 , e4 , e5 , e6 , e7 , e8 } and its incidence relation given as:𝑒1 =< 𝑏, 𝑎 >, 𝑒2 =

< 𝑑, 𝑎 >, 𝑒3 =< 𝑏, 𝑐 >, 𝑒4 =< 𝑑, 𝑐 >, 𝑒5 =< 𝑐, 𝑓 >, 𝑒6 =, < 𝑓, 𝑓 >, 𝑒7 =< 𝑒, 𝑐
> & 𝑒8 =< 𝑐, 𝑒 >. Discuss all the term.
Sol:
𝑏 𝑒3 𝑐 𝑒5 𝑓 𝑒6

𝑔
𝑒1 𝑒4 𝑒8

𝑒7
𝑎 𝑒2 𝑑 𝑒

# 3140708 (DM)  Unit 5 – Graph theory 17


Method 1 ⇛ Example 5(continue)
𝑏 𝑒3 𝑐 𝑒5 𝑓 𝑒6  All edges of G are directed.

𝑒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

 Degree  Regular Graph


 Handshaking Theorem  Complete Graph
 2nd Theorem of Graph Theory  Subgraph
 Outdegree, Indegree and Total Degree  Converse of a Directed Graph
 Degree Sum Formula for Directed Graph  Isomorphic Graph
Order of a Graph and Size of a Graph

The number of vertices in G is called


order of a graph G.
The order of G is denoted by V G .

The number of edges in G is called


size of a graph G.
The size of G is denoted by E G . G
Here V G = 5 & E G = 9.

# 3140708 (DM)  Unit 5 – Graph theory 20


Degree of a Vertex

Let G be an undirected graph then the


degree of a vertex 𝑣 ∈ G is defined as
the number of edges incident on 𝑣.

The degree of a vertex 𝑣 ∈ G is denoted


by d(𝑣) OR dG 𝑣 OR deg 𝑣 .

Note Self-loop will be counted twice in the G


degree of a corresponding vertex. 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
# 3140708 (DM)  Unit 5 – Graph theory 21
Odd Vertex, Even Vertex, Isolated Vertex and Pendant Vertex
A vertex with odd degree is called an odd vertex.

A vertex with even degree is called an even vertex.

A vertex with zero degree is called an isolated vertex.

A vertex with one degree is called a pendant vertex.

# 3140708 (DM)  Unit 5 – Graph theory 22


Odd Vertex, Even Vertex, Isolated Vertex and Pendant Vertex

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

𝑣2 , 𝑣3 , 𝑣6 & 𝑣9 are odd vertices in G.


𝑣1 , 𝑣4 & 𝑣5 are even vertices in G.
𝑣7 & 𝑣8 are isolated vertices in G.
𝑣3 & 𝑣6 are pendant vertices in G.

# 3140708 (DM)  Unit 5 – Graph theory 23


Handshaking Theorem(Degree Sum Formula/𝟏𝐬𝐭 Theorem of Graph Theory)

Statement Any undirected graph G with ‘𝑛’ vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛 and ‘𝑒’ edges,
𝑛

෍ d 𝑣𝑖 = d 𝑣1 + d 𝑣2 + ⋯ + d 𝑣𝑛 = 2𝑒.
𝑖=1

Proof Let G = V, E be an undirected graph with ‘𝑛’ vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛


and ‘𝑒’ edges.
Let ek ∈ E, then ‘𝑒𝑘 ’ have two terminated vertices say 𝑣𝑖 & 𝑣𝑗 .
By definition of degree of vertex, 𝑒𝑘 is count in the degree of 𝑣𝑖 and
degree of 𝑣𝑗 .

# 3140708 (DM)  Unit 5 – Graph theory 24


Handshaking Theorem(Degree Sum Formula/𝟏𝐬𝐭 Theorem of Graph Theory)

Proof Continue

Therefore, every edge of G is count twice and if 𝑒𝑘 is a loop then it is also


count twice.
Hence, the sum of degree of all the vertices of G is twice the number of edges.
𝑛

i.e. ෍ d 𝑣𝑖 = 2𝑒 .
𝑖=1

# 3140708 (DM)  Unit 5 – Graph theory 25


Example on Handshaking Theorem

Example Verify Handshaking theorem for the following graph G.

Solution In G, the number of vertices is 𝑛 = 9


and the number of edges is 𝑒 = 10.
𝑛=9

෍ 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𝑒.

Hence, Handshaking theorem is verified for the graph G.


# 3140708 (DM)  Unit 5 – Graph theory 26
𝟐𝐧𝐝 Theorem of Graph Theory

Statement In any undirected graph G, the number of odd vertices is even.

Proof Let G = V, E be a graph with ‘𝑛’ vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛 and ‘𝑒’ edges.


𝑛

By first theorem of graph theory ෍ d 𝑣𝑖 = 2𝑒 .


𝑖=1

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

Hence, the number of odd vertices


G has 4(even) number of odd vertices.
is even in any undirected graph G.

# 3140708 (DM)  Unit 5 – Graph theory 28


Outdegree and Indegree of a Vertex for a Directed Graph
Let G be a directed graph then for any vertex 𝑢 ∈ G, the number of edges which
have 𝑢 as their initial vertex is called the outdegree of the vertex 𝑢.
OR
In a directed graph G, the number of edges directed outwards vertex 𝑢 is called
outdegree of the vertex 𝑢.

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 .

Note The total degree of an isolated vertex is 0.


The vertex with degree 1 is known as pendant vertex.

# 3140708 (DM)  Unit 5 – Graph theory 30


Example of Degree for a Directed Graph

Example Find outdegree, indegree and total degree of all the vertices of following
graph G.
Solution

Vertex Outdegree Indegree Total degree


𝑣1 d+ 𝑣1 = 1 d− 𝑣1 =1 d 𝑣1 = 2
𝑣2 d+ 𝑣2 = 2 d− 𝑣2 =2 d 𝑣2 = 4
𝑣3 d+ 𝑣3 = 1 d− 𝑣3 =1 d 𝑣3 = 2
𝑣4 d+ 𝑣4 = 2 d− 𝑣4 =2 d 𝑣4 = 4 G
# 3140708 (DM)  Unit 5 – Graph theory 31
Degree Sum Formula for a Directed Graph

Statement In a directed graph G with ‘𝑛’ vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛 and ‘𝑒’ edges,


𝑛 𝑛 𝑛
෍ d+ 𝑣𝑖 = ෍ d− 𝑣𝑖 = 𝑒 and ෍ d 𝑣𝑖 = 2𝑒.
𝑖=1 𝑖=1 𝑖=1

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.

# 3140708 (DM)  Unit 5 – Graph theory 32


Degree Sum Formula for a Directed Graph
Proof

Let G = V, E be a directed graph with ‘𝑛’ vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛 and ‘𝑒’ edges.


A vertex has indegree corresponding to simple edge is exactly 1.
Once an edge is count for indegree it will not count for outdegree for the same
vertex.
When we are adding the indegree of vertex, each edge is counted exactly once.
Hence, total of indegree of all the vertices is same as the number of edges.

# 3140708 (DM)  Unit 5 – Graph theory 33


Degree Sum Formula for a Directed Graph
𝑛
Proof continue
i.e. ෍ d− 𝑣𝑖 = 𝑒 .
𝑖=1

Similarly, we can prove ෍ d+ 𝑣𝑖 = 𝑒 .


𝑖=1
𝑛 𝑛 𝑛
෍ d 𝑣𝑖 = ෍ d+ 𝑣𝑖 + ෍ d− 𝑣𝑖
𝑖=1 𝑖=1 𝑖=1

= 𝑒 + 𝑒 = 2𝑒.

# 3140708 (DM)  Unit 5 – Graph theory 34


Example of Degree Sum Formula for a Directed Graph

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

# 3140708 (DM)  Unit 5 – Graph theory 35


Regular Graph

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

# 3140708 (DM)  Unit 5 – Graph theory 37


Complete Graph

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

# 3140708 (DM)  Unit 5 – Graph theory 39


Complete Graph
n n−1
The complete graph with n vertices K n has edges.
2

The complete graph with n = 5 vertices K 5 has 𝑒1 𝑒2


5 5−1 5 4 𝑒8
= = 10 edges. 𝑒6 𝑒10
2 2
𝑒5 𝑒9 𝑒7 𝑒3

𝑒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.

Note The graph G as well as the null


graph obtained by deleting all the
edges of G are subgraphs of G.

Other subgraphs of G can be obtained


by deleting certain vertices and edges
Here H is subgraph of G. of G.

# 3140708 (DM)  Unit 5 – Graph theory 41


Vertex Deleted Subgraph
The graph obtain by deletion of a vertex 𝑣 from a given graph G is called a
vertex deleted subgraph of G. It is denoted by G − 𝑣 .

𝑎 𝑎

𝑒 𝑏 𝑒 𝑏

𝑑 𝑐 𝑑 𝑐
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 }

# 3140708 (DM)  Unit 5 – Graph theory 44


Complement of a Subgraph
Let G be a complete graph and S be a subgraph of G. The complement of a
subgraph S is obtained by remove all edges of G which is present in S.
It is denoted by ഥ
S.
a a a

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 .

# 3140708 (DM)  Unit 5 – Graph theory 48


Example of Non-Isomorphic Graph

𝟏 𝐯𝟏 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 >.

# 3140708 (DM)  Unit 5 – Graph theory 49


Example of Isomorphic Graph
4 Vertex Edge
u3 u4
Mapping Mapping
2 3 1 → 𝑢3 < 1, 3 > → < 𝑢3 , 𝑢4 >
2 → 𝑢1 < 1, 2 > → < 𝑢3 , 𝑢1 >
3 → 𝑢4 < 2, 4 > → < 𝑢1 , 𝑢2 >
1 u2 u1
4 → 𝑢2
G1 G2 < 3, 4 > → < 𝑢4 , 𝑢2 >

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 .

# 3140708 (DM)  Unit 5 – Graph theory 50


Properties of Isomorphic Graph
(1). Two isomorphic graphs must have the same number of vertices.
(2). Two isomorphic graphs must have the same number of edges.
(3). Two isomorphic graphs must have an same number of vertices with given degree.
Note Above properties are necessary properties if two graphs becomes isomorphic.
But it is not sufficient.
Example
Here in G and H, above three properties
are satisfied. But they are not isomorphic.

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

# 3140708 (DM)  Unit 5 – Graph theory 52


Method 2 ⇛ Example 7 (a)(continue)
Solution Vertex Edge Mapping
Mapping
1→𝑎 𝑒1 → 𝑒1′ 𝑒6 → 𝑒6′
2→𝑏 𝑒2 → 𝑒2′ 𝑒7 → 𝑒7′
3→𝑐 𝑒3 → 𝑒3′ 𝑒8 → 𝑒8′
4→𝑑 𝑒4 → 𝑒4′ 𝑒9 → 𝑒9′
5→𝑒 𝑒5 → 𝑒5′
6→𝑓
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 .
# 3140708 (DM)  Unit 5 – Graph theory 53
Method 2 ⇛ Example 2
Question Draw all possible different simple digraphs having three vertices and up to
isomorphism. Show that there is only one digraph with no edges, one with
one edge, four with two edges, four with three edges, four with four edges,
one with five edges & one with six edges.

Solution one digraph with no edge one digraph with one edge

# 3140708 (DM)  Unit 5 – Graph theory 54


Method 2 ⇛ Example 2(continue)
Four digraphs with two edges Four digraphs with three edges

# 3140708 (DM)  Unit 5 – Graph theory 55


Method 2 ⇛ Example 2(continue)
Four digraphs with four edges One digraph with five edges

One digraph with six edges

# 3140708 (DM)  Unit 5 – Graph theory 56


Method - 3
Path, Reachability & Connectedness

 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.

Paths originating at 1 and ending at 3 are


P1 = (< 1,2 >, < 2,3 >)
P2 = (< 1,4 >, < 4,3 >)
P3 = (< 1,2 >, < 2,4 >, < 4,3 >)
P4 = (< 1,2 >, < 2,4 >, < 4,1 >, < 1,4 >, < 4,3 >)
P5 = (< 1,2 >, < 2,4 >, < 4,1 >, < 1,2 >, < 2,3 >)
P6 = (< 1,1 >, < 1,1 >, … , < 1,2 >, < 2,3 >)
# 3140708 (DM)  Unit 5 – Graph theory 58
Length of a Path
The number of edges appearing in the sequence of a path is called the length of
a path.

Paths originating at 1 and ending at 3 are

P1 = (< 1,2 >, < 2,3 >)


⇒ Length of P1 = 2

P2 = (< 1,2 >, < 2,4 >, < 4,3 >)


⇒ Length of P2 = 3

# 3140708 (DM)  Unit 5 – Graph theory 59


Simple Path and Elementary Path
A path in a digraph in which all A path in a digraph in which all the
the edges are distinct is called vertices through which it traverses
are distinct is called an elementary
a simple path (edge simple).
path (vertex simple).

Paths originating at 1 and ending at 3 are


P1 = (< 1,2 >, < 2,3 >)
P2 = (< 1,4 >, < 4,3 >)
P3 = (< 1,2 >, < 2,4 >, < 4,3 >)
P4 = (< 1,2 >, < 2,4 >, < 4,1 >, < 1,4 >, < 4,3 >)
The paths P1 , P2 & P3 are elementary and simple.
The path P4 is simple but not elementary.
# 3140708 (DM)  Unit 5 – Graph theory 60
Remarks on Path and Cycle(Circuit)
Every elementary path of a digraph is also a simple path.
If there exist a path from u to v then there must be an elementary path from u to v.

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.

# 3140708 (DM)  Unit 5 – Graph theory 62


Method 3 ⇛ Example 2
Question Give all elementary cycles for the following graph. Obtain an acyclic
digraph by deleting one edge of the given digraph.
Solution
𝑣1 𝑣4 𝑣5
The elementary cycles of the given graph are

C1 = (< 𝑣1 , 𝑣2 >, < 𝑣2 , 𝑣3 >, < 𝑣3 , 𝑣4 >, < 𝑣4 , 𝑣1 >)


𝑣2 𝑣3
C2 = (< 𝑣1 , 𝑣2 >, < 𝑣2 , 𝑣4 >, < 𝑣4 , 𝑣1 >)
G

# 3140708 (DM)  Unit 5 – Graph theory 63


Method 3 ⇛ Example 2 (Continue)
The edge deleted subgraph of G which is acyclic are 𝐆 −< 𝒗𝟏 , 𝒗𝟐 > and
𝐆 −< 𝒗𝟒 , 𝒗𝟏 >.

𝑣1 𝑣4 𝑣5 𝑣1 𝑣4 𝑣5 𝑣1 𝑣4 𝑣5

𝑣2 𝑣3 𝑣2 𝑣3 𝑣2 𝑣3
G 𝐆 −< 𝒗𝟏 , 𝒗𝟐 > 𝐆 −< 𝒗𝟒 , 𝒗𝟏 >

# 3140708 (DM)  Unit 5 – Graph theory 64


Method 3 ⇛ Example 3
Question Prove that in a simple digraph, the length of any elementary path is less
than or equal to 𝑛 − 1, where 𝑛 is the number of vertices in the graph.
Similarly, the length of any elementary cycle does not exceed 𝑛.
Solution In any elementary path, vertices appearing in the sequence are distinct.
The number of distinct vertices in any elementary path of length 𝑘 is 𝑘 + 1.
Since there are only 𝑛 distinct vertices in the graph. So, the length of any
elementary path is less than or equal to 𝑛 − 1.
For any elementary cycle of length 𝑛, the sequence contains 𝑛 distinct vertices.
So, the length of any elementary cycle does not exceed 𝑛.

# 3140708 (DM)  Unit 5 – Graph theory 65


Reachability
A vertex 𝑣 of a digraph is said to be reachable(accessible) from the vertex 𝑢 of
the same digraph if there exist at least one path from 𝑢 to 𝑣.

Reachability is a binary relation on the set of vertices of a simple digraph.


𝑣1 𝑣4
Reachability is reflexive and transitive relation.

Reachability is not necessarily symmetric nor it is anti-symmetric.

𝑣2 𝑣3

# 3140708 (DM)  Unit 5 – Graph theory 66


Geodesic, Distance and Diameter
If a vertex 𝑣 is a reachable from the vertex 𝑢 then a path of minimum length from
𝑢 to 𝑣 is called a geodesic.

The length of a geodesic from the vertex 𝑢 to the vertex 𝑣 is called the distance
and it is denoted by 𝐝 < 𝒖, 𝒗 >.

The diameter of a digraph G =< V, E > is given by 𝛅 = 𝐦𝐚𝐱 𝐝 𝒖, 𝒗 .


𝒖, 𝒗 ∈ 𝐕

It is assumed that d < 𝑢, 𝑢 > = 0 for any vertex 𝑢.

# 3140708 (DM)  Unit 5 – Graph theory 67


Properties of Reachability
If 𝑣 is reachable from 𝑢 then d < 𝑢, 𝑣 > satisfies the following properties:
𝑣1 𝑣4
d < 𝑢, 𝑣 > ≥ 0
d < 𝑢, 𝑢 > = 0
d < 𝑢, 𝑣 > + d < 𝑣, 𝑤 > ≥ d < 𝑢, 𝑤 > ( Triangle inequality )

𝑣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

# 3140708 (DM)  Unit 5 – Graph theory 69


Method 3 ⇛ Example 6

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 }

# 3140708 (DM)  Unit 5 – Graph theory 70


Node Base
In a digraph G =< V, E >, a subset X ⊆ V is called a node base if reachable set
of X is V and no proper subset of X has this property.

𝒗𝟏 𝒗𝟐 𝒗𝟓 𝒗𝟔 𝒗𝟗
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

A digraph is called weakly connected


(connected) if it is connected as an Weakly
undirected graph in which the direction Connected
of edges is neglected.

A digraph is called unilaterally


connected if for any pair of vertices of Weakly and
Unilaterally
the graph at least one of the vertex of
Connected
pair is reachable from the other vertex.

# 3140708 (DM)  Unit 5 – Graph theory 74


Strongly Connected Digraph
A digraph is called strongly connected if Weakly,
for any pair of vertices of graph both the Unilaterally
vertices of the pair are reachable from and Strongly
one another. Connected

Every strongly connected digraph is unilaterally connected and weakly


connected both but converse may not be true.
Every unilaterally connected digraph is weakly connected but converse may not
be true.

# 3140708 (DM)  Unit 5 – Graph theory 75


Strong Component of a Digraph
For a digraph a maximal strongly connected subgraph is called a strong
component.
Note Maximal strongly connected subgraph of G it means a subgraph S of G which
is strongly connected but no super graph of S which is strongly connected.
There are four strong components of 𝐆 which are
3 4 6
3

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

# 3140708 (DM)  Unit 5 – Graph theory 77


Weak Component of a Digraph
For a digraph a maximal weakly connected subgraph is called a weak
component.
Note Maximal weakly connected subgraph of G it means a subgraph S of G which
is weakly connected but no super graph of S which is weakly connected.
There is one weak component of 𝐆 which is
3 4 6 3 4 6

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

# 3140708 (DM)  Unit 5 – Graph theory 79


Method 3 ⇛ Example 8 (Continue)
Question Determine whether the digraph G2 is strongly, weakly and unilaterally
connected.
Solution G2 is not strongly connected because not existing path from 𝑣5 to 𝑣4 .
𝑣1 𝑣4
𝑣5 Path from 𝑣1 → 𝑣2 , 𝑣1 → 𝑣3 , 𝑣1 → 𝑣4 & 𝑣1 → 𝑣5 is exist
in G2 .
Path from 𝑣2 → 𝑣3 , 𝑣2 → 𝑣4 & 𝑣2 → 𝑣5 is exist in G2 .
𝑣2 𝑣3 Path from 𝑣3 → 𝑣4 & 𝑣3 → 𝑣5 is exist in G2 .
G2 Path from 𝑣4 → 𝑣5 is exist in G2 .
⇒ G2 is unilaterally connected implies weakly connected.
# 3140708 (DM)  Unit 5 – Graph theory 80
Application of Simple Digraph to Represent Resource Allocation Status of an Operating System

We shall show how a simple digraph can be used to represent the resource
allocation status of an operating system.

In a multi programmed computer system it appears that several programs are


executed at one time. In reality, the programs are sharing the resources of the
computer system such as tape units, disk devices, the central processor, main
memory and compilers.

A special set of programs called an operating system controls the allocation of


these resources to the programs. When a program requires the use of a certain
resource and the operating system must ensure that the request is satisfied.

# 3140708 (DM)  Unit 5 – Graph theory 81


Application of Simple Digraph to Represent 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

Let Pt = {p1 , p2 , … , pm } represent the set of programs in the computer system


at time t. Let At ⊆ Pt be the set of active programs or programs that have been
allocated at least a portion of their resource requests at time t. Let Rt
= {r1 , r2 , … , rn } represent the set of resources in the system at time t.

An allocation graph Gt is a directed graph representing the resource allocation


status of the system at time t and consisting of a set of vertices V = R t and a
set of edges E. Each resource is represented by a vertex of the graph. There is a
directed edge from vertex ri to rj if and only if there is a program pk in At that
has been allocated resource ri but is waiting for rj .

# 3140708 (DM)  Unit 5 – Graph theory 83


Example of Simple digraph Represent Resource Allocation Status of an Operating System

Let R t = {r1 , r2 , r3 , r4 } and At = {p1 , p2 , p3 , p4 } then the resource allocation


status is given in following allocation graph at a time t.

𝑟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 .

𝑝3 𝑝4 p4 has resource r3 and requires r1 and r4 .


𝑟3

# 3140708 (DM)  Unit 5 – Graph theory 84


Method - 4
Matrix Representation of a Graph

 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.

An alternating method of representing graphs using matrices has several


advantages. It is easy to store and manipulate matrices and the graphs
represented by them in a computer.

Well known operations of matrix algebra can be used to calculate paths, cycles
and other characteristics of a graph.

# 3140708 (DM)  Unit 5 – Graph theory 86


Adjacency Matrix of a Graph
The adjacency matrix of an undirected graph G = V, E with 𝑛 vertices
𝑣1 , 𝑣2 , … , 𝑣𝑛 and without parallel edges is an 𝑛 × 𝑛 matrix A = 𝑎𝑖𝑗 whose
elements 𝑎𝑖𝑗 are given as follows:
1 ; if there is an edge between 𝑣𝑖 and 𝑣𝑗
𝑎𝑖𝑗 =
0 ; otherwise
The adjacency matrix of a directed graph G = < V, E > with 𝑛 vertices
𝑣1 , 𝑣2 , … , 𝑣𝑛 and without parallel edges is an 𝑛 × 𝑛 matrix A = 𝑎𝑖𝑗 whose
elements 𝑎𝑖𝑗 are given as follows:
1 ; if < vi , vj > ∈ E (there is an edge from vi to vj )
𝑎𝑖𝑗 =
0 ; otherwise
# 3140708 (DM)  Unit 5 – Graph theory 87
Adjacency Matrix of a Graph
𝑣1 𝑣2 𝑣3 𝑣𝑛

.
.
.
𝑣1 𝑎11 𝑎12 𝑎13 𝑎1𝑛

.
.
.
𝑣2 𝑎21 𝑎22 𝑎23 𝑎2𝑛

.
.
.
𝑣3 𝑎31 𝑎32 𝑎33 𝑎3𝑛

.
.
.
A = 𝑎𝑖𝑗 𝑛×𝑛
= . . . . .
. . . . .
. . . . .
𝑣𝑛 𝑎𝑛1 𝑎𝑛2 𝑎𝑛3 𝑎𝑛𝑛

.
.
.
𝑛×𝑛

# 3140708 (DM)  Unit 5 – Graph theory 88


Example of an Adjacency Matrix for an Undirected Graph
Question Find an adjacency matrix for the following undirected graph.
𝑣1 𝑣4
Solution
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5
𝑣1 𝑎011 𝑎112 𝑎1
13 𝑎114 𝑎015
𝑣2 𝑣3 𝑣5
𝑣2 𝑎121 𝑎022 𝑎123 𝑎024 𝑎025

A = 𝑎𝑖𝑗 = 𝑣3 𝑎131 𝑎132 𝑎033 𝑎134 𝑎035


5×5
𝑣4 𝑎141 𝑎042 𝑎143 𝑎044 𝑎145
𝑣5 𝑎0
51 𝑎052 𝑎53
0 𝑎154 𝑎055

# 3140708 (DM)  Unit 5 – Graph theory 89


Example of an Adjacency Matrix for a Directed Graph
Question Find an adjacency matrix for the following directed graph.

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

𝑣4 𝑎141 𝑎042 𝑎043 𝑎044

# 3140708 (DM)  Unit 5 – Graph theory 90


Remarks on Adjacency Matrix for a Directed Graph
The sum of all 1’s in a row indicates the outdegree of the corresponding vertex.
The sum of all 1’s in a column indicates the indegree of the corresponding vertex.

𝑣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

# 3140708 (DM)  Unit 5 – Graph theory 91


Remarks on Adjacency Matrix
For a given digraph G = < V, E >, an adjacency matrix depends upon the
ordering of the elements of V. For different ordering of the elements of V we get
different adjacency matrices of the same graph G.

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.

If a digraph is antisymmetric, then aij = 1 implies aji = 0 and aij = 0 implies


that aji = 1 for all i and j.

# 3140708 (DM)  Unit 5 – Graph theory 93


Remarks on Adjacency Matrix and Boolean Matrix
If G = < V, E > is a simple digraph whose adjacency matrix is A then the
෩ is the converse of G which is AT .
adjacency matrix of G

Any matrix whose elements are either 0 OR 1 is called a Boolean matrix.

# 3140708 (DM)  Unit 5 – Graph theory 94


Path(Reachability) Matrix of a Directed Graph
Let G = < V, E > be a simple digraph with 𝑛 vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛 . An 𝑛 × 𝑛
matrix P = 𝑝𝑖𝑗 whose elements 𝑝𝑖𝑗 are given by
1 ; if there is a path from 𝑣𝑖 and 𝑣𝑗
𝑝𝑖𝑗 =
0 ; otherwise

is called the path(reachability) matrix of the graph G.

# 3140708 (DM)  Unit 5 – Graph theory 95


Example of a Path Matrix for a Directed Graph
Question Find a path matrix for the following directed graph.
𝑣1 𝑣2
Solution
𝑣1 𝑣2 𝑣3 𝑣4
𝑣1 𝑝011 𝑝112 𝑝113 𝑝0
14

𝑣2 𝑝021 𝑝122 𝑝123 𝑝024 𝑣4 𝑣3


P = 𝑝𝑖𝑗 =
4×4 𝑣3 𝑝031 𝑝132 𝑝133 𝑝034
𝑣4 𝑝141 𝑝142 𝑝143 𝑝044

# 3140708 (DM)  Unit 5 – Graph theory 96


Importance of an Adjacency Matrix for a Directed Graph
Let G = < V, E > be a simple digraph with 𝑛 vertices and A be the adjacency
matrix of graph G then the path matrix P of graph G can be calculated from the
matrix B𝑛 = A + A2 + A3 + ⋯ + An by choosing 𝑝𝑖𝑗 = 1 if the element 𝑏𝑛 𝑖𝑗 of
B𝑛 is non-zero and 𝑝𝑖𝑗 = 0 if the element 𝑏𝑛 𝑖𝑗 of B𝑛 is zero.

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.

# 3140708 (DM)  Unit 5 – Graph theory 97


Example Find the path matrix of given digraph using adjacency matrix. Also find
the number of paths of length 4 between 𝑣2 & 𝑣4 from the adjacency
matrix and mention it from the given digraph. 𝑣 𝑣
1 2
Solution The adjacency matrix of given digraph is
𝑣1 𝑣2 𝑣3 𝑣4
𝑣1 0 1 0 0
𝑣2 0 0 1 1
A= 𝑣4 𝑣3
𝑣3 1 1 0 1
𝑣4 1 0 0 0

The number of vertices in given digraph is 𝑛 = 4.


Hence, 𝐁𝒏 = B4 = A + A2 + A3 + A4 .
# 3140708 (DM)  Unit 5 – Graph theory 98
Solution Continue

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

B4 = A + A2 + A3 + A4 From B4 we conclude that all the entries


are non-zero implies all the entries of a
3 4 2 3 path matrix P are 1(one).
5 5 4 6
⇒ B4 = 1 1 1 1
7 7 4 7
1 1 1 1
3 2 1 2 𝑖. 𝑒. , P =
1 1 1 1
1 1 1 1

# 3140708 (DM)  Unit 5 – Graph theory 100


Example Find the path matrix of given digraph using adjacency matrix. Also find
the number of paths of length 4 between 𝑣2 & 𝑣4 from the adjacency
matrix and mention it from the given digraph. 𝑣 𝑣 1 2

Solution The number of paths of length 4 between 𝑣2 & 𝑣4


is 3 which is the element of 2𝑛𝑑 row and 4𝑡ℎ
column of A4 .
The path of length 4 from 𝑣2 to 𝑣4 are 𝑣4 𝑣3
P1 = < 𝒗𝟐 , 𝑣3 >, < 𝑣3 , 𝑣1 >, < 𝑣1 , 𝑣2 >, < 𝑣2 , 𝒗𝟒 >
1 2 1 1
P2 = < 𝒗𝟐 , 𝑣4 >, < 𝑣4 , 𝑣1 >, < 𝑣1 , 𝑣2 >, < 𝑣2 , 𝒗𝟒 > 2 2 2 3
4
P3 = < 𝒗𝟐 , 𝑣3 >, < 𝑣3 , 𝑣2 >, < 𝑣2 , 𝑣3 >, < 𝑣3 , 𝒗𝟒 > A = 3 3 2 3
2 1 0 1
# 3140708 (DM)  Unit 5 – Graph theory 101
Remarks on a Path Matrix for a Directed Graph
The path matrix only shows the presence or absence of at least one path
between a pair of vertices and also presence or absence of a cycle at any
vertex. It does not show all the paths that may exist. In this sense a path matrix
does not give complete information about a graph as does the adjacency matrix.
The path matrix is important in its own right.

It may be remarked that if we are interested in knowing the reachability of one


vertex from another, it is sufficient to calculate B𝑛−1 = A + A2 + ⋯ + An−1 ,
because a path of length 𝑛 cannot be elementary for graph with 𝑛 vertices.

For the purpose of reachability, every vertex is assumed to be reachable from


itself.
# 3140708 (DM)  Unit 5 – Graph theory 102
Warshall’s Algorithm to Produce a Path Matrix
Let G be a directed graph with 𝑛 vertices 𝑣1 , 𝑣2 , … , 𝑣𝑛 . Suppose we want to find
the path matrix P of the graph G. Warshall gave an algorithm which is much
more efficient than calculating the powers of the adjacency matrix A.

First we define 𝑛 + 1 square Boolean matrices P0 , P1 , P2 , … , Pn as follows: Let


Pk 𝑖, 𝑗 denotes the 𝑖𝑗𝑡ℎ entry of the matrix P𝑘 . Then we define:

1 ; if there is a simple path from 𝑣𝑖 and 𝑣𝑗 which does not


P𝑘 𝑖, 𝑗 = use any other vertices except possible 𝑣1 , 𝑣2 , … , 𝑣𝑘 .
0 ; otherwise

# 3140708 (DM)  Unit 5 – Graph theory 103


Warshall’s Algorithm to Produce a Path Matrix
i.e. P0 𝑖, 𝑗 = 1 if there is an edge from 𝑣𝑖 to 𝑣𝑗 .

P1 𝑖, 𝑗 = 1 if there is a simple path from 𝑣𝑖 to 𝑣𝑗 which does not use any vertex
except possibly 𝑣1 .

P2 𝑖, 𝑗 = 1 if there is a simple path from 𝑣𝑖 to 𝑣𝑗 which does not use any


vertices except possibly 𝑣1 and 𝑣2 . And so on.

Observe that the first matrix P0 = A is the adjacency matrix of G. Furthermore,


since G has only 𝑛 vertices, the last matrix P𝑛 = P is the path matrix of G.

# 3140708 (DM)  Unit 5 – Graph theory 104


Warshall’s Algorithm to Produce a Path Matrix
Warshall observed that P𝑘 𝑖𝑗 = 1 only if one of the following two cases occurs:

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.

These two cases are pictured as follows:


𝟏 . 𝑣𝑖 → ⋯ → 𝑣𝑗 and 𝟐 . 𝑣𝑖 → ⋯ → 𝑣𝑘 → ⋯ → 𝑣𝑗 .

# 3140708 (DM)  Unit 5 – Graph theory 105


Warshall’s Algorithm to Produce a Path Matrix
Here in first case → ⋯ → denotes part of a simple path which does not use any
other vertices except possibly 𝑣1 , 𝑣2 , … , 𝑣𝑘−1 . Accordingly the elements of P𝑘
can be obtained by the following formula.

P𝑘 𝑖, 𝑗 = P𝑘−1 𝑖, 𝑗 ∨ P𝑘−1 𝑖, 𝑘 ∧ P𝑘−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 .

# 3140708 (DM)  Unit 5 – Graph theory 106


Method 4 ⇛ Example 5
Question Apply Warshall’s algorithm to produce a path matrix for the given graph.
Solution 𝑣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

# 3140708 (DM)  Unit 5 – Graph theory 107


Method 4 ⇛ Example 5 (Continue)
Question Apply Warshall’s algorithm to produce a path matrix for the given graph.
Solution Continue P1 𝑖, 𝑗 = P0 𝑖, 𝑗 ∨ P0 𝑖, 1 ∧ P0 1, 𝑗
P1 3, 2 = P0 3, 2 ∨ P0 3, 1 ∧ P0 1, 2 = 0 ∨ 1 ∧ 1 = 0 ∨ 1 = 1
𝑣1 𝑣2 𝑣3 𝑣4 𝑣5 𝑣1 𝑣2 𝑣3 𝑣4 𝑣5
𝑣1 𝑣1
0 1 0 0 0 0 1 0 0 0 𝑣1
𝑣2 0 0 1 0 𝑣2 0 0 1 0
0 0 𝑣5
𝑣2
P0 = 𝑣3 1 0 0 0 0 ⇒ P1 = 𝑣3 1 1
0 0 0 0
𝑣4 0 0 0 0 1 𝑣4 0 0 0 0 1
𝑣4 𝑣3
𝑣5 0 1 0 0 0 𝑣5 0 1 0 0 0
Intermediate 𝑣1
# 3140708 (DM)  Unit 5 – Graph theory 108
Method 4 ⇛ Example 5 (Continue)
Question Apply Warshall’s algorithm to produce a path matrix for the given graph.
Solution Continue P2 𝑖, 𝑗 = P1 𝑖, 𝑗 ∨ P1 𝑖, 2 ∧ P1 2, 𝑗 𝑣1

𝑣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

Which is required path matrix for the given graph.

# 3140708 (DM)  Unit 5 – Graph theory 113


Method 4 ⇛ Example 2
Que: Find A and 𝐴2 without a matrix multiplication for the given digraph. Where, A
is an adjacency matrix.
𝑣1 𝑣2

A ⇒ reachable by using 1 edge


A2 ⇒ reachable by using 2 edges

𝑣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.

A directed tree is an connected acyclic digraph


which has one vertex with indegree ‘0’, while all the
other vertices have indegree ‘1’.
A directed tree which has a vertex with indegree ‘0’
is called a root.
Note Every directed tree must have at least one
vertex. An isolated vertex is also a directed tree.

# 3140708 (DM)  Unit 5 – Graph theory 117


Forest
A set of disjoint trees is called a forest.

# 3140708 (DM)  Unit 5 – Graph theory 118


Leaf, Branch and Level in a Directed Tree
In a directed tree, any vertex which has 𝒗𝟓 𝒗𝟖
𝒗𝟒
outdegree ‘ 0 ’ is called a terminal Level 𝟑
Leaf
vertex(leaf).
𝒗𝟐 𝒗𝟑 𝒗𝟏𝟎 𝒗𝟗 𝒗𝟕 Level 𝟐
The vertex which is not leaf in a
directed tree is called branch vertex.
𝒗𝟏 Level 𝟏
𝒗𝟔
The level of any vertex is the length of
its path from the root. Branch
𝒗𝟎
The level of the root in a directed tree Root Level 𝟎

is 0, while the level of any vertex is Directed tree


equal to its distance from the root.
# 3140708 (DM)  Unit 5 – Graph theory 119
Path in a Directed Tree
Observe that all the paths in a 𝒗𝟒 𝒗𝟓 𝒗𝟖
Level 𝟑
directed tree are elementary and
length of a path from any vertex 𝒗𝟐 𝒗𝟏𝟎
𝒗𝟑 𝒗𝟗 𝒗𝟕 Level 𝟐
to another vertex if such a path
exists is the distance between
the vertex, because a directed 𝒗𝟏 𝒗𝟔 Level 𝟏

tree is acyclic.
Level 𝟎
𝒗𝟎

Undirected tree

# 3140708 (DM)  Unit 5 – Graph theory 120


Different Representation of a Tree
Tree Venn Diagram List of Books
𝑣0 𝑣0
𝑣1
𝑣2
𝑣1 𝑣6 𝑣7 𝑣8 𝑣3
𝑣4
𝑣2 𝑣5 𝑣9 𝑣5
𝑣10
𝑣4 𝑣3 𝑣6
𝑣2 𝑣7 𝑣6
𝑣3 𝑣1 𝑣7
𝑣10 𝑣8
𝑣9 𝑣0 𝑣9
𝑣10
𝑣4 𝑣5 𝑣8
Method A Method C

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.

Binary tree full(complete) binary tree


# 3140708 (DM)  Unit 5 – Graph theory 122
m-ary Tree and Complete(full) m-ary Tree
In a directed tree the outdegree of every vertex is less than or equal to 𝑚 then
the tree is called a 𝒎-ary tree.
If the outdegree of every vertex is exactly equal to 0 OR 𝑚 then the tree is called
a full(complete) 𝒎-ary tree.

𝟑-ary tree full(complete) 𝟑-ary tree


# 3140708 (DM)  Unit 5 – Graph theory 123
Descendent and Son of any Vertex
The vertex which is reachable from Ancestor
‘𝑢’ is called descendent of ‘𝑢’.
𝒖
The vertex which is reachable from ‘ 𝑢 ’
through single edge is called son of ‘𝑢’.
Son
If we consider 𝑚-ary tree in which the 𝑚
sons of any vertex are assumed to have 𝑚
distinct positions are taken into account then
the tree is called a positional 𝐦-ary tree. Descendent

# 3140708 (DM)  Unit 5 – Graph theory 124


Representation of vertices in a Binary Tree

0 1 0 1

The above figures shows all possible arrangements of sons of a vertex of a


binary tree.

# 3140708 (DM)  Unit 5 – Graph theory 125


Representation of vertices of a Binary Tree

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.

# 3140708 (DM)  Unit 5 – Graph theory 126


Representation of vertices of a Binary Tree
Any son of a vertex 𝑢 has a string which is prefixed by the string of 𝑢. The string
of any terminal vertex is not prefixed to the string of any other vertex.
The set of string corresponding to the terminal vertices forms a prefix code.

Here, the prefix code of the given binary


tree is 000,001,01,10,110,111 .
0 1
A similar representation of vertices of a
positional 𝑚-ary tree by means of string
00 11
01 10 over the numbers 0, 1, 2, … , 𝑚 − 1 is
possible.
000 001 110 111
# 3140708 (DM)  Unit 5 – Graph theory 127
Convert any m-ary Tree to a Binary Tree

𝟏. 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.

# 3140708 (DM)  Unit 5 – Graph theory 128


1

2 5
3 4 Stage-1
Given Tree

6 7 8 9 10 11

Delete all the branches except the left most branches.


Draw edges from a vertex to vertex on the right, if situated at the same level.

# 3140708 (DM)  Unit 5 – Graph theory 129


1

6 3

4
7 8
5 Stage-1

9 The left son is the vertex which is


immediately below the given node.
10 The right son is the vertex to the immediate
right of the given vertex.
Binary Tree 11
# 3140708 (DM)  Unit 5 – Graph theory 130
Method - 6
Tree Traversal

 Linked Representation of a Binary Tree


 Tree Traversal
 Pre-order Traversal
 In-order Traversal
 Post-order Traversal
Linked Representation of a Binary Tree
A
Linked Representation
A
B E

F B E
C D

G C D F

H
G
Binary Tree
H

# 3140708 (DM)  Unit 5 – Graph theory 132


Tree Traversal and Pre-order Traversal
Tree traversal is a procedure by which every vertex is processed exactly once in
some systematic manner. A

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

Traverse the left sub-tree in in-order.


B E
Process the root vertex.
F
Traverse the right sub-tree in in-order.
C D
G

In-order 𝐂 𝐁 𝐃 𝐀 𝐄 𝐆 𝐇 𝐅

# 3140708 (DM)  Unit 5 – Graph theory 134


Post-order Traversal
Post-order traversal A

Traverse the left sub-tree in post-order. B E


Traverse the right sub-tree in post-order.
F
Process the root vertex.
C D
G

Post-order 𝐂 𝐃 𝐁 𝐇 𝐆 𝐅 𝐄 𝐀

# 3140708 (DM)  Unit 5 – Graph theory 135


 Extra Method
Question Define a tree. Prove that if a graph G has one and only one path between
every pair of vertices then G is a tree.
Solution A connected graph without any cycle is called a tree.
Assume that there is exactly one path between
every pair of vertices in a graph G.
Therefore, G is connected. − − → 𝟏
Suppose G has a cycle then there is at least one pair of
vertices 𝑎 and 𝑏 such that there are two distinct path between
𝑎 and 𝑏.
Which is not possible. So, G is acyclic. − − → 𝟐
From 1 & 2 we conclude that G is a tree.

# 3140708 (DM)  Unit 5 – Graph theory 137


Question Define a tree. Prove that there is one and only one path between every
pair of vertices in a tree T.
Solution A connected graph without any cycle is called a tree.
Let us consider T is a tree.
Therefore,T is connected and there is no cycle in T.
Suppose that there exist two distinct path between the
vertices 𝑎 and 𝑏 in T.
The union of these two distinct paths will contain a cycle in T.
Which is not possible. Because T is acyclic.
Hence, there is one and only one path between every pair of
vertices in a tree T.

# 3140708 (DM)  Unit 5 – Graph theory 138


Question Find the number of edges in G if it has 5 vertices and each of degree 2.
Solution Here, 𝑛 = V G = 5 and 𝑒 is the number of edges in G.
Let V = 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 , 𝑣5 and d 𝑣𝑖 = 2 for each 𝑖 = 1 to 5.
5
By first theorem of graph theory ෍ d 𝑣𝑖 = 2𝑒 .
𝑖=1

⇒ 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.

# 3140708 (DM)  Unit 5 – Graph theory 139


Question Does a 3 −regular graph with 5 vertices exist.
Solution No
Let G = V, E be a graph with 5 vertices 𝑣1 , 𝑣2 , 𝑣3 , 𝑣4 , 𝑣5 and d 𝑣𝑖 = 3 for
each 𝑖 = 1 to 5.
5

By first theorem of graph theory ෍ d 𝑣𝑖 = 2𝑒 = even


𝑖=1

⇒ 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy