You could use the following interesting result . Let AA denote the adjacency matrix of your graph. Then, the (i,j)(i,j) entry of the matrix AnA^n will denote the number of walks of length nn from vertex ii to vertex jj.