On this page
An adjacency matrix turns a drawing of dots and lines into a grid of 0s and 1s. Put a 1 in row i, column j when vertex i is joined to vertex j, and 0 otherwise. As the Wikipedia article on adjacency matrices states, the (i, j) entry of Aⁿ gives the number of walks of length n from vertex i to vertex j.
Why does A^k count walks of length k?
Use induction on k. For k = 1, Aᵢⱼ is 1 exactly when there is a one-edge walk from i to j.
Now suppose (Aᵏ)ᵢₘ counts the walks of length k from i to m. Every walk of length k + 1 from i to j is a walk of length k from i to some vertex m, followed by one edge from m to j. Matrix multiplication adds up those cases:
(Aᵏ⁺¹)ᵢⱼ = Σₘ (Aᵏ)ᵢₘ · Aₘⱼ
Each term is "ways to reach m in k steps" times "1 if m is next to j".
How do you compute A² and A³ for a small graph?
Start with a 4-cycle: label the corners of a square 1, 2, 3, 4 in order around the square. Row 1 of A is (0, 1, 0, 1), and row 1 of A² is (2, 0, 2, 0). The 2 in position (1, 1) is the walks 1→2→1 and 1→4→1; the 2 in position (1, 3) is 1→2→3 and 1→4→3. Cube it and you get A³ = 4A. Each corner has 2 neighbours, so 2ᵏ walks of length k leave any corner.
Next, take a triangle 1, 2, 3 and hang vertex 4 off vertex 3. The rows of A are (0, 1, 1, 0), (1, 0, 1, 0), (1, 1, 0, 1) and (0, 0, 1, 0).
A² has rows (2, 1, 1, 1), (1, 2, 1, 1), (1, 1, 3, 0) and (1, 1, 0, 1).
A³ has rows (2, 3, 4, 1), (3, 2, 4, 1), (4, 4, 2, 3) and (1, 1, 3, 0). Check two entries by listing the walks:
(A³)₁₄ = 1: the only walk is 1→2→3→4.
(A³)₃₄ = 3: the walks are 3→1→3→4, 3→2→3→4 and 3→4→3→4.
For high powers, finding large powers of a matrix by diagonalisation saves the repeated multiplication.
How does trace(A³)/6 count triangles?
A closed walk of length 3 must go once around a triangle. Each triangle is counted 6 times in the trace: once from each of its 3 corners, in each of 2 directions. So the number of triangles in an undirected graph is trace(A³) divided by 6, and divided by 3 for a directed graph, as the adjacency matrix article explains.
In the tailed triangle, the diagonal of A³ is (2, 2, 2, 0). The trace is 6, so there is 6 ÷ 6 = 1 triangle. In the 4-cycle the trace of A³ is 0: no triangles.
How does the largest eigenvalue give the growth rate of walks?
Multiply A by the all-ones vector again and again; each product lists the walks of the next length starting at each vertex. For the tailed triangle, the totals for k = 1 to 6 are 8, 18, 38, 84, 180 and 394.
The ratios of successive totals (2.25, 2.11, 2.21, 2.14, 2.19) close in on about 2.17. The characteristic polynomial of this A is x⁴ − 4x² − 2x + 1, and its largest root is about 2.1701.
The exponential growth rate of the powers Aᵏ is controlled by the eigenvalue of largest absolute value, as the article on the Perron–Frobenius theorem puts it. So for a connected graph like this one, the number of walks of length k grows roughly like λ₁ᵏ, where λ₁ is the largest eigenvalue. Our 2×2 walk-through of the Perron–Frobenius theorem shows why, for positive matrices, that eigenvalue is real and positive.
The adjacency matrix article adds two checks. The largest eigenvalue is at most the maximum degree, and for a d-regular graph it equals d. The 4-cycle is 2-regular, so λ₁ = 2, matching the 2ᵏ walks we counted. The tailed triangle has maximum degree 3, and 2.17 sits below it. For what other eigenvalues say about a graph, read about the graph Laplacian and the Fiedler vector.
How do you check A^k by hand?
Symmetry: for an undirected graph, every power of A must be symmetric.
Degrees: the diagonal of A² must equal the degree of each vertex.
One entry by listing: pick the smallest non-zero entry and write out its walks.
Parity: if the graph has no odd cycle, every diagonal entry of an odd power must be 0.
If the step from "sum over m" to "walks through m" still feels slippery, the Fermi Concept Library gives each concept in mathematics its own lesson and its place in the map, so you can revisit matrix multiplication or eigenvalues. The Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.
Draw a graph of your own with five vertices, compute A³, and check its trace against the triangles you can see.



