MATPMD2 Notes Session 2 With Additional Notes-4
MATPMD2 Notes Session 2 With Additional Notes-4
2 Adjacency matrices
The (0, 1)- adjacency matrix of a graph G is A = (aij ) where aij = 1 if vertex i is adjacent to vertex j,
and aij = 0 otherwise. Knowledge of the adjacency matrix of a graph is equivalent to knowledge of
the graph. To obtain an adjacency matrix from a graph we need to assume some arbitrary order to the
vertices which can be labelled accordingly. Re-labelling the vertices will require re-ordering the rows
and columns of the adjacency matrix resulting in a similar matrix. The question of whether or not two
graphs are isomorphic is equivalent to the question of whether or not two matrices are similar. Both
problems have the same level of complexity.
Some notation.
1. We write the matrix A = (aij ). This means that A is a matrix (or an array) with (i, j)th entry aij .
The (i, j) - entry lies in row i, column j. For example a14 is the entry in matrix A in row 1 and
column 4, ahk is the entry in row h column k of the matrix A.
(p)
2. We will use the notation aij to denote the (i, j)th entry in the matrix Ap .
3. The trace of a matrix is the sum of its diagonal entries, i.e the sum of the entries on the main
diagonal from top left to bottom right.
Proposition.
Let G be an n-vertex graph with adjacency matrix A. The (i, j)-entry of Ak is the number of i − j
walks of length k.
Proof : by induction on k
True for k = 1 since A1 = A = (aij ) where aij = 1 when i ∼ j and 0 otherwise.
Suppose k > 1 and result holds for k − 1.
Then
k k−1 (k)
A = A A = aij
where n
X
(k) (k−1)
aij = aih ahj .
h=1
(k)
Thus aij counts the number of walks of length k − 1 from i to h which continue with edge hj.
These are the walks of length (k − 1) + 1 = k from i to j as required.
UNIVERSITY OF STIRLING MATPMD2
Computing Science & Mathematics 2020
UNIVERSITY OF STIRLING MATPMD2
Computing Science & Mathematics 2020
Example 2.3
Find the number of walks of length 4 from vertex 3 to vertex 4 in the following graph.
Solution
UNIVERSITY OF STIRLING MATPMD2
Computing Science & Mathematics 2020
Remark Let G be an n-vertex graph with adjacency matrix A. Then the trace(A2 ) is twice the number
of edges in G, and the trace(A3 ) is six times the number of 3-cycles in G.
To see why we first consider diagonal entries of A2 which give the number of walks of length two
from a vertex to itself. Such walks must go from the vertex to its neighbour and back again so for each
vertex it counts
P the number of neighbours of that vertex; it counts the degree of that vertex. Thus
2
trace(A ) = deg(v) = 2m where m is the number of edges of G.
The diagonal entries of A3 give the number of walks of length three from a vertex to itself. Consider
the 3-cycle ijki
This 3-cycle yields 6 walks of length three from a vertex to itself, namely ijki, ikji, jikj, jkij, kijk
and kjik and so contributes a count of 6 to the trace(A3 ). This is true for every 3-cycle in G and so the
trace(A3 ) is six times the number of 3-cycles in G