[Math] Use adjacency matrix to find the number of paths

graph theorymatrices

I have this course notes exercise in graph theory asking to:

  1. Find the adjacency matrix of the graph A.
  2. Use the adjacency matrix to find the number of paths of length 2 joining a and b.

Graph A :

Graph A

If anyone could explain how to do both of these steps that would be great. I think I know how to do the first part – Add a 0 to the matrix where no edge appears between two vertices and add a 1 where an edge does appear between two vertices.

The second question is the one I'm stuck on so if anyone could explain what I need to do to achieve the answer that would be great.

Apologies for using paint to draw my graph.

Note: graph is undirected.

Thanks very much.

Best Answer

Hint

To get a path of length $n$ from adjacency matrix $A$ you need to consider $A^n$ as a Boolean product of matrices.

The idea for $n=2$ is as follows: Suppose $u$ is adjacent to $v$ and $v$ is adjacent to $w$, then there is a path of length $2$ from $u$ to $w$. What the matrix product does is to capture all such paths.