TITLE: Large power of an adjacency matrix
QUESTION [7 upvotes]: The adjacency matrix I have at the start is
[0,1,0,0,0]
[0,0,1,0,0]
[1,0,0,1,1]
[0,0,0,0,0]
[0,0,0,0,0]  
I don't understand why this matrix^9999 equals
[1,0,0,1,1]
[0,1,0,0,0]
[0,0,1,0,0]
[0,0,0,0,0]
[0,0,0,0,0]    
or why this matrix^33334 equals
[0,1,0,0,0]
[0,0,1,0,0]
[1,0,0,1,1]
[0,0,0,0,0]
[0,0,0,0,0]  
Can someone please explain what is happening?

REPLY [6 votes]: Vertex $1$ is connected to $2,$ $2$ to $3,$ $3$ to $1, 4, 5,$ and $4$ and $5$ have no out edges, so your graph is a directed cycle with a couple of hairs pointing out. The number of paths of length $k$ from $1$ to $2$ is $1$ if $k = 1 \mod 3,$ and $0$ otherwise. same from $2$ to $3,$ same from $3$ to $1.$ Similarly for paths from $1$ to $3,$(except $k$ has to be $2 \mod 3$), etc.

REPLY [5 votes]: Since the adjacency matrix $\mathrm A$ is not symmetric, we have a directed graph.

Given a positive integer $k$, the $(i,j)$-th entry of $\mathrm A^k$ gives us the number of directed walks of length $k$ from $i$ to $j$. Given the cycle $1 \to 2 \to 3 \to 1$, the entry $(\mathrm A^k)_{11}$ should be $1$ when $k$ is a multiple of $3$ and $0$ when $k$ is not a multiple of $3$. Using SymPy, we can verify this:
>>> A = Matrix([[0,1,0,0,0],
                [0,0,1,0,0],
                [1,0,0,1,1],
                [0,0,0,0,0],
                [0,0,0,0,0]])
>>> A**2
[0  0  1  0  0]
[             ]
[1  0  0  1  1]
[             ]
[0  1  0  0  0]
[             ]
[0  0  0  0  0]
[             ]
[0  0  0  0  0]
>>> A**3
[1  0  0  1  1]
[             ]
[0  1  0  0  0]
[             ]
[0  0  1  0  0]
[             ]
[0  0  0  0  0]
[             ]
[0  0  0  0  0]
>>> A**4
[0  1  0  0  0]
[             ]
[0  0  1  0  0]
[             ]
[1  0  0  1  1]
[             ]
[0  0  0  0  0]
[             ]
[0  0  0  0  0]
>>> A**5
[0  0  1  0  0]
[             ]
[1  0  0  1  1]
[             ]
[0  1  0  0  0]
[             ]
[0  0  0  0  0]
[             ]
[0  0  0  0  0]
>>> A**6
[1  0  0  1  1]
[             ]
[0  1  0  0  0]
[             ]
[0  0  1  0  0]
[             ]
[0  0  0  0  0]
[             ]
[0  0  0  0  0]

Note that $9999$ is a multiple of $3$, whereas $33334$ is not.