PGD01C01
Module 2 · Graph Theory

Matrix Representation of Graphs

Core Titles
Key headlines and terms for quick recall
  • Adjacency matrix AA (size n×nn \times n, aij=1a_{ij}=1 if edge)
  • Incidence matrix BB (n×mn \times m)
  • Circuit matrix
  • Cut-set matrix
  • Path matrix
  • Ak[i][j]A^k[i][j] counts walks of length kk from ii to jj
Basic Idea
What it is, why it matters, how it works

Why represent a graph as a matrix?

Matrices let us apply linear algebra to graphs — count walks, find connected components, study spectra, run algorithms.

Adjacency matrix AA

For a graph on nn vertices, AA is the n×nn \times n matrix where Aij={1if (vi,vj)E0otherwiseA_{ij} = \begin{cases} 1 & \text{if } (v_i, v_j) \in E \\ 0 & \text{otherwise} \end{cases} For undirected graphs, AA is symmetric. For weighted graphs, store the weight instead of 1.

Key fact. AijkA^k_{ij} counts the number of walks of length kk from viv_i to vjv_j.

Incidence matrix BB

Rows = vertices, columns = edges. For undirected graph: Bij=1B_{ij} = 1 if viv_i is incident to edge eje_j, else 0. For digraph: +1+1 for tail, 1-1 for head.

Circuit (cycle) matrix

Rows = fundamental circuits, columns = edges. Entry is 1 if the edge is in the circuit. Useful in network analysis.

Cut-set matrix

Rows = fundamental cut-sets, columns = edges. Entry 1 if the edge crosses the cut.

Path matrix

Pij=1P_{ij} = 1 if there is a path from viv_i to vjv_j (the transitive closure of AA). Computed by repeatedly OR-ing A,A2,A3,A, A^2, A^3, \dots or by Warshall's algorithm.

Why this matters in Data Science

Graph neural networks operate on adjacency matrices. PageRank, spectral clustering and recommender systems use eigenvectors of AA or the Laplacian L=DAL = D - A.

Mind Map
Visual structure of the concept
MATRIX REPRESENTATIONS
├── Adjacency A  (n × n)
│   ├── Aᵢⱼ = 1 if edge
│   ├── Undirected ⇒ symmetric
│   ├── Aᵏ counts walks of length k
│   └── Laplacian  L = D − A
├── Incidence B (n × m)
│   ├── Undirected: 1 if vertex on edge
│   └── Directed: −1 tail / +1 head
├── Circuit matrix
├── Cut-set matrix
└── Path matrix (transitive closure of A)
Exam Q&A
Part A (2 marks) and Part B (20 marks) style questions

Part A (2 marks each)

Q1. Define adjacency matrix of a graph. For a graph on nn vertices, the n×nn \times n matrix AA with Aij=1A_{ij} = 1 if there is an edge between viv_i and vjv_j, else 0.

Q2. What does Aij2A^2_{ij} represent? The number of walks of length 2 from viv_i to vjv_j.

Q3. Difference between incidence and adjacency matrix. Adjacency is vertex × vertex; incidence is vertex × edge.

Q4. For an undirected graph, what property does AA have? AA is symmetric.


Part B (20 marks)

Q. Describe the matrix representations of a graph — adjacency, incidence, circuit and path matrix. Take the graph GG with V={1,2,3,4}V = \{1,2,3,4\} and edges {(1,2),(2,3),(3,4),(4,1),(1,3)}\{(1,2),(2,3),(3,4),(4,1),(1,3)\} and write its adjacency and incidence matrices. Use A2A^2 to count walks of length 2 from vertex 1.

(i) Adjacency matrix. VV × VV. Entry Aij=1A_{ij} = 1 if {i,j}\{i, j\} is an edge.

A=(0111101011011010)A = \begin{pmatrix} 0 & 1 & 1 & 1 \\ 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \end{pmatrix}

(Vertex 1 is adjacent to 2, 3, 4; vertex 2 to 1, 3; vertex 3 to 1, 2, 4; vertex 4 to 1, 3.)

(ii) Incidence matrix. VV × EE. Label edges e1=(1,2),e2=(2,3),e3=(3,4),e4=(4,1),e5=(1,3)e_1=(1,2), e_2=(2,3), e_3=(3,4), e_4=(4,1), e_5=(1,3).

B=(10011110000110100110)B = \begin{pmatrix} 1 & 0 & 0 & 1 & 1 \\ 1 & 1 & 0 & 0 & 0 \\ 0 & 1 & 1 & 0 & 1 \\ 0 & 0 & 1 & 1 & 0 \end{pmatrix}

(iii) Circuit matrix — rows index fundamental circuits (cycles), columns index edges. For each cycle, mark the edges in it. The cycle 12311{-}2{-}3{-}1 uses e1,e2,e5e_1, e_2, e_5, giving row (1,1,0,0,1)(1,1,0,0,1), and so on.

(iv) Path matrix is the transitive closure of AA (here all entries become 1 since GG is connected).

Walks of length 2 from vertex 1. Compute the first row of A2A^2:

A1,12=kA1kAk1=00+11+11+11=3A^2_{1,1} = \sum_k A_{1k} A_{k1} = 0\cdot 0 + 1\cdot 1 + 1\cdot 1 + 1\cdot 1 = 3 (walks 1211\to 2\to 1, 1311\to 3\to 1, 1411\to 4\to 1).

A1,22=kA1kAk2=0+0+1+0=1A^2_{1,2} = \sum_k A_{1k} A_{k2} = 0 + 0 + 1 + 0 = 1 (walk 1321\to 3\to 2).

A1,32=0+1+0+1=2A^2_{1,3} = 0 + 1 + 0 + 1 = 2 (walks 1231\to 2\to 3 and 1431\to 4\to 3).

A1,42=0+0+1+0=1A^2_{1,4} = 0 + 0 + 1 + 0 = 1 (walk 1341\to 3\to 4).

So from vertex 1 there are 3 closed, 1 to vertex 2, 2 to vertex 3, 1 to vertex 4 — total of 7 walks of length 2.