Skip to main content
SAGeneral MathematicsSyllabus dot point

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.

Generated by Claude Opus 4.76 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. Building an adjacency matrix
  3. Counting two-step walks with matrix powers
  4. Reading the diagonal and the row sums
  5. Direct plus indirect connections

What this dot point is asking

You must build an adjacency matrix from a graph, interpret its entries, and use A2A^2 or higher powers to count multi-step connections.

Building an adjacency matrix

A network (graph) has vertices joined by edges. Its adjacency matrix AA 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 AA to BB is also a link from BB to AA). For a directed network the entry in row ii, column jj counts only edges pointing from ii to jj, 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 A2A^2 in row ii, column jj counts exactly these two-edge walks from ii to jj.

Reading the diagonal and the row sums

The diagonal entries of A2A^2 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 AA are also useful: in an undirected network the sum of row ii gives the degree of vertex ii, the number of edges meeting it.

Direct plus indirect connections

A common task is to add matrices to combine route lengths. For example, A+A2A + A^2 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?"