The
adjacency matrix of a graph is an n x n matrix
A = (ai,j) in which the entry ai,j =1
if there is an edge from vertex i to vertex j and is 0
if there is no edge from vertex i to vertex j. By the way, a
matrix with only zeros and ones as entries is called a (0,1) matrix.
In the applet below draw a few graphs and the applet will display the
adjacency matrix of a graph you draw.
To use the program Petersen to see the adjacency matrix of a graph, you should first get the program to draw the graph and then click Properties and then Adjacency Matrix.
|
|
| Fig. 10, The cube and its adjacency matrix |
.We shall see that bij is the number of paths of length 2 from i to j. (If i=j then you just get the degree of the vertex). How does this work? Let us start with an easy graph -- just three vertices labeled 1,2,3 and think about the quantity a1 2*a23. Here are the possibilities:
|
|
|
|
Now let us be more general: Consider any three vertices i, j, and k.We have that aik = 1 if there is an edge from i to k , otherwise aik = 0. (You can also say the same for akj). Now if you multiply aik and ajk you get that aik * akj is either zero or one. It will be one if both aik and akj are one, otherwise it will be zero. So aik * akj = 1 if and only if there is a path of length 2 from vertex i to j via k and is zero otherwise. Notice that since in our adjacency matrices the diagonal entries are zero aii and ajj are zero so when we get aik * akj = 1 the vertex k is neither i nor j. Now think about the sum
ai1*a1j contributes a 1 if there is a path of length 2 from
i to j via 1 (and 0 if not)
ai2*a2j contributes a 1 if there is a path of length 2 from
i to j via 2 (and 0 if not)
...
ain*anj contributes a 1 if there is a path of length 2 from
i to j via n (and 0 if not).
Have we counted them all? Sure because if there is a path from i to j of length 2 it must go via either vertex 1,2,3, ...or n so it must have been counted. Were any counted more than once? Surely not since a path of length 2 from i to j could not go via more than one vertex before getting to j -- it would have to be of length at least 3 to do that. This leads us to conclude that bij is the number of paths of length 2 from i to j.
Now that you get the idea you will understand the applet that follows: You will draw a graph in the left window and in the middle window will appear its adjacency matrix and then in the right window the square of its adjacency matrix. Play with it a while and discuss with your classmates to make sure you understand what all the numbers mean.
.If a graph has adjacency matrix A, how is the trace of A³ related to the number of triangles in a graph?[Hint]
© C. Mawata