0% found this document useful (0 votes)
19 views90 pages

DMGT_CO5_Matrix Representation of Graphs

Module-5 covers the matrix representation of graphs, including incidence matrices, circuit matrices, path matrices, and adjacency matrices for both directed and undirected graphs. It also discusses graph theoretic algorithms, chromatic numbers, and properties of different matrix types. The module includes examples, exercises, and theorems related to graph matrices and their applications.

Uploaded by

samarth soni
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)
19 views90 pages

DMGT_CO5_Matrix Representation of Graphs

Module-5 covers the matrix representation of graphs, including incidence matrices, circuit matrices, path matrices, and adjacency matrices for both directed and undirected graphs. It also discusses graph theoretic algorithms, chromatic numbers, and properties of different matrix types. The module includes examples, exercises, and theorems related to graph matrices and their applications.

Uploaded by

samarth soni
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/ 90

Module-5.

Matrix representation of graphs

Dr.E.Prasad
Asst Professor, Dept of Mathematics
VIT Bhopal

Module Title
Module-5. Matrix representation of graphs

Syllabus

Incidence matrix – sub matrices – circuit matrix – path matrix –


adjacency matrix. Chromatic number
Directed graphs, Graph Theoretic algorithms: Digraphs – types of
digraphs – directed paths and connectedness –Euler graphs –
adjacency matrix of a digraph - tournament. Algorithms--
connectedness and components – spanning tree – fundamental
circuits – cut vertices – directed circuits – shortest path algorithm

Syllabus Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Part-1

Graph Matrices

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

1.Incidence Matrix-Undirected Graph

Let G be a graph with n vertices, m edges and without self-loops. The incidence matrix A of
G is an nXm matrix A = [𝑎𝑖𝑗 ] whose n rows correspond to the n vertices and the m columns
correspond to m edges such that

It is also called vertex-edge incidence matrix and is denoted by A(G).

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example1:Find the incidence matrix of the graph G1

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example1:Find the incidence matrix of the graph G1

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Exercise1: Find the incidence matrix of the following graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Ans:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example2:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Exercise2:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

2.Incidence Matrix-Directed Graph

Let G be a graph with n vertices, m edges and without self-loops. The incidence matrix of
G is an nXm matrix B= [𝑏𝑖𝑗 ] whose n rows correspond to the n vertices and the m columns
correspond to m edges such that

−1, 𝑒𝑑𝑔𝑒 𝑒𝑗 𝑎𝑤𝑎𝑦 𝑓𝑟𝑜𝑚 𝑡𝑕𝑒 𝑣𝑒𝑟𝑡𝑒𝑥 𝑣𝑖


𝑏𝑖𝑗 = 1, 𝑒𝑑𝑔𝑒 𝑒𝑗 𝑡𝑜𝑤𝑎𝑟𝑑𝑠 𝑡𝑕𝑒 𝑣𝑒𝑟𝑡𝑒𝑥 𝑣𝑖
0, 𝑒𝑑𝑔𝑒 𝑒𝑗 𝑛𝑜𝑡 𝑟𝑒𝑙𝑎𝑡𝑒𝑑 𝑡𝑕𝑒 𝑣𝑒𝑟𝑡𝑒𝑥 𝑣𝑖

It is also called vertex-edge incidence matrix and is denoted by B(G).

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example3

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example4:Find the incidence matrix of the following graphs

Ans(a)

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Exercise2

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example5

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Exercise3

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

*Theorem1:
If A is an Incidence matrix of the directed graph G then the number of trees = 𝐴𝐴𝑇

Example6:Find the incidence matrix of the following graphs and also find its number of tree

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Sol:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Properties1:

A complete incidence matrix [A]ij a graph has some properties by which one can
identify whether the given matrix is a complete incidence matrix or not. These
properties are:
1. The sum of values of [A]ij of any column is equal to zero.
2. For a closed loop system, the determinant of [A]ij is always zero.
3. The rank of the complete incidence matrix [A]ij is n-1 where n=number of nodes in
the graph.

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example7 : Find the incidence matrix of the following circuit

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Sol :

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

3.Loop Matrix or Circuit Matrix-Undirected Matrix


Circuit can be defined as “A close walk in which no vertex/edge can appear twice”.
If edge of graph is a part of given circuit then put 1 else 0.

1, 𝐼𝑓 𝑎 𝑐𝑖𝑟𝑐𝑢𝑖𝑡 𝑐𝑜𝑛𝑡𝑎𝑖𝑛 𝑒𝑑𝑔𝑒


𝐶𝑖𝑗 =
0, 𝐼𝑓 𝑎 𝑐𝑖𝑟𝑐𝑢𝑖𝑡 𝑛𝑜𝑡 𝑐𝑜𝑛𝑡𝑎𝑖𝑛 𝑒𝑑𝑔𝑒

Example8

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example8

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Ans:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

4.Loop Matrix or Circuit Matrix-directed Matrix


Circuit can be defined as “A close walk in which no vertex/edge can appear twice”.
If edge of graph is a part of given circuit then put 1 else 0.

1, 𝐼𝑓 𝑎 𝑐𝑖𝑟𝑐𝑢𝑖𝑡 𝑐𝑜𝑛𝑡𝑎𝑖𝑛 𝑒𝑑𝑔𝑒


𝐶𝑖𝑗 =
0, 𝐼𝑓 𝑎 𝑐𝑖𝑟𝑐𝑢𝑖𝑡 𝑛𝑜𝑡 𝑐𝑜𝑛𝑡𝑎𝑖𝑛 𝑒𝑑𝑔𝑒

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example 9

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Ans:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs
5.Cyclic Matrix

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs
The cycle matrix is

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Definition 6

Example 10

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example 11:Find Path matrix from v3 to v4 of the following graph

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Ans:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Path Matrix Observations

Properties:https://www.geneseo.edu/~aguilar/public/notes/Graph-Theory-HTML/ch2-the-
adjacency-matrix.html

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

7. Adjacency Matrix-Undirected

The adjacency matrix is symmetric, which will be true for the adjacency matrix of any undirected
graph
Example 12

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example 13

Example 14

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

8. Adjacency Matrix-directed

An adjacency matrix for a directed graph will not necessarily be symmetric, because an arc
from ni to nj does not imply an arc from nj and ni

Example 15

Example 16

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

9. Adjacency Matrix-Weighted Graph

Example 17

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs
10. Cut Matrix

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

11.Fundamental Cut-Set Matrix

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs
*12.Chromatic number

Definition. We say that a graph G is k-colorable if we can assign the colors1 {1, . . . k} to the
vertices in V (G), in such a way that every vertex gets exactly one color and no edge in E(G)
has both of its endpoints colored the same color. We call such a coloring a proper coloring,
though sometimes where it’s clear what we mean we’ll just call it a coloring. Alternately,
such graphs are sometimes called k-partite.
For a fixed graph G, if k is the smallest number such that G admits a k-coloring, we say that
the chromatic number of G is k, and write χ(G) = k.

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Find chromatic number of the following graph

https://www.gatevidyalay.com/graph-coloring-algorithm-how-to-find-chromatic-
number/

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

1.Complete Graph (Kn): The complete graph on n vertices has chromatic number n. To see that

it is at least n, simply paint each of the vertices {v1, . . . vn} of V (Kn) a different color (say, vi is

painted i;) then every edge trivially has two endpoints of different colors. To see that this is

necessary, take any proper coloring of Kn, and look at any vertex vi : because it’s connected to

every other vertex, it cannot be the same color as any other vertex (and therefore must have a

different color than every other vertex, which forces n colors.)

2. Bipartite graphs: By definition, every bipartite graph with at least one edge has chromatic

number 2.

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

The chromatic number of a graph G is the smallest number of colors needed to color the
vertices of so that no two adjacent vertices share the same color

The chromatic number of a graph G is most commonly denoted ꭓ (G), but occasionally
also γ(G)

Empty graphs have chromatic number 1, while non-empty bipartite graphs have chromatic
number 2

1. If number of vertices in cycle graph is even, then its chromatic number = 2.


2. If number of vertices in cycle graph is odd, then its chromatic number = 3.
3. Chromatic Number of any Planar Graph = Less than or equal to 6
4. Chromatic Number of any Complete Graph= Number of vertices in that Complete Graph
5. Chromatic Number of any Bipartite Graph=2
6. Chromatic Number of any tree=2

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Prove the following:

1. Every tree with 2 or more vertices is 2 chromatic


2. A graph with at least one edge is 2 chromatic if and only if it has no circuits of odd length
(proofs related notes I have shared )

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Directed Graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Connectivity in digraphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Eulerian and Hamilton digraphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Algorithm[DFS and BFS]


For
Connected Components

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Reference
1. https://www.lkouniv.ac.in/site/writereaddata/siteContent/202004160614287266anshu_s
ingh_engg_Graph_traversal.pdf
2. https://resources.mpi-
inf.mpg.de/departments/d1/teaching/ws14/AlgoDat/materials/components.pdf
3. https://www.sfu.ca/~arashr/parminder.pdf
4. https://www.javatpoint.com/bfs-vs-dfs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

“Dijkstra’s Algorithm”
For
shortest path
-Undirected Graph

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

1. Ans. From A to F is 14

Ans. From S to B is 15
2.

Ans: From 0 to 8 is 11
3.

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Ans: v1 to v6 is 80
4.

5.
Ans

6.

Ans

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Ans:11
7.

8.
Ans.20

9.

Ans:14

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

10. Ans: 11

11.
Ans: 11

12.
Ans: 14

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

“Dijkstra’s Algorithm”
For
shortest path
-Directed Graph

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

1.
Ans. From S to B is 9

2.
Ans. From a to h is 161

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

3.
Ans. From A to E is 18

4. Ans. From 1 to 6 is 9

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

5.
Ans. From A to E is 18

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

“ Floyd- Warshall ”
For
shortest path Algorithm

(OR)
Robert Floyd and Stephen Warshall

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example1: Using Floyd Warshall Algorithm, find the shortest path distance between
every pair of vertices.

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Ans:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example2: Using Floyd Warshall Algorithm, find the shortest path distance between
every pair of vertices.

Ans:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example3: Using Floyd Warshall Algorithm, find the shortest path distance between
every pair of vertices.

Ans:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Example4: Using Floyd Warshall Algorithm, find the shortest path distance between
every pair of vertices.

Example5: Using Floyd Warshall Algorithm, find the shortest path distance between
every pair of vertices.

Ans:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs
Using Floyd Warshall Algorithm, find the shortest path distance between every pair of
vertices.

Example8:
Example6:

Example7:

Dr.E.Prasad ,Asst Professor,VIT Bhopal


Module-5. Matrix representation of graphs

Dr.E.Prasad ,Asst Professor,VIT Bhopal

You might also like