How can matrices store the connections in a network and count routes between vertices?
Represent networks with adjacency matrices and use matrix powers to count walks of a given length between vertices.
How to build an adjacency matrix from a network, read direct connections, and use powers of the matrix to count the number of two-step and longer walks between vertices.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
You must build an adjacency matrix from a graph, interpret its entries, and use or higher powers to count multi-step connections.
Building an adjacency matrix
A network (graph) has vertices joined by edges. Its adjacency matrix is square, with one row and one column per vertex. Each entry counts the edges joining that pair of vertices.
For an undirected network the matrix is symmetric (a link from to is also a link from to ). For a directed network the entry in row , column counts only edges pointing from to , so the matrix need not be symmetric.
Counting two-step walks with matrix powers
A walk of length 2 uses two edges, passing through one intermediate vertex. The entry of in row , column counts exactly these two-edge walks from to .
Reading the diagonal and the row sums
The diagonal entries of count two-step walks that return to the starting vertex. In the example each diagonal entry is 2, because each town can reach two others and come straight back, giving two such loops.
Row sums of are also useful: in an undirected network the sum of row gives the degree of vertex , the number of edges meeting it.
Why matrix powers count walks
The walk-counting property follows directly from how matrix multiplication works. The entry in row , column of is the sum over every intermediate vertex of - the number of edges from to times the number from to . Each such product counts the two-edge routes that pass through , and summing over all counts every two-step walk from to . The same reasoning extends to higher powers: sums over all pairs of intermediate vertices, so it counts three-step walks, and so on. Understanding this explains why the technique works rather than treating it as a rule to memorise.
Directed networks and dominance
For a directed network, where edges have a direction, the adjacency matrix is generally not symmetric, and its powers count directed walks that respect the arrows. A common application is a dominance matrix for a round-robin competition, where if player beat player . The row sums of give first-order dominance (direct wins), and the row sums of combine direct wins with "wins over someone who beat someone", giving an overall ranking. This is a standard SACE context for adjacency matrices beyond simple road maps.
Direct plus indirect connections
A common task is to add matrices to combine route lengths. For example, gives the number of routes of length 1 or 2 between each pair of vertices, useful for asking "in how many ways can I get from P to R in at most two steps?"
Exam-style practice questions
Practice questions written in the style of SACE Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
SACE 20234 marksCalculator-assumed. Towns P, Q, R have direct roads P to Q, Q to R and P to R, with the adjacency matrix . (a) Find . (b) State how many two-step routes go from P to R and describe one.Show worked answer →
(a) . (2 marks)
(b) The entry in row P (row 1), column R (column 3) of is , so there is one two-step route: P to Q to R. (2 marks)
Marks: two for squaring the matrix, two for reading the correct entry and describing the route.
SACE 20223 marksCalculator-assumed. For the adjacency matrix , find the number of routes of length 1 or 2 from Q to R using .Show worked answer →
. [2 marks]
The entry in row Q (row 2), column R (column 3) is , so there are 2 routes of length at most 2 from Q to R (the direct road Q to R, and Q to P to R). [1 mark]
