Theorem : Suppose G is a graph with vertices {v1,v2,…,vn} and A is the $n \times n$ adjacency matrix of G. G can be directed or undirected and multiple edges and loops are allowed. Then the (i,j)th entry of $\text{A}^r$ is the number of different paths of length r from $v_i$ to $v_j$ .
Let $\text{A}$ be Adjacency matrix for this graph,
$\text{A}$ = $\begin{bmatrix} 0 &1 &1 &1 &0 &0 \\ 1 &0 &1 &0 & 1 &0 \\ 1& 1 &0 & 1 & 0 &1 \\ 1& 0& 1 &0 & 0 &1 \\ 0&1 &0 &0 &0 &1 \\ 0& 0 &1 &1 &1 &0 \end{bmatrix}$
then for finding paths of length 2 we need to find $\text{A}^2$
$\text{A}^2 =$ $\begin{bmatrix} 3 &1 & 2 & 1 & 1 &2 \\ 1& 3 &1 &2 &0 &2 \\ 2& 1 &4 & 2 & 2 & 1\\ 1 &2 & 2 & 3 & 1 &1 \\ 1& 0 & 2 & 1 &2 &0 \\ 2& 2 &1 &1 & 0 & 3 \end{bmatrix}$
Now add the elements of the upper triangular or lower triangular of $\text{A}^2$
$1 + 2+ 1 + 1 + 2 + 1 + 2 + 0 + 2 + 2 + 2 + 1 + 1 + 1 + 0 = 19$