All revision notes topics

3.15 Adjacency matrices and walksIB Maths: Applications and Interpretation HL: Revision notes

Section 1

Adjacency matrices

The adjacency matrix of a graph with nn vertices is an n×nn\times n matrix whose entry in row ii, column jj is the number of edges joining vertex ii to vertex jj. For a simple undirected graph the entries are 0 or 1, the leading diagonal is all zeros, and the matrix is symmetric. For a directed graph the entry counts edges from ii to jj, so the matrix need not be symmetric. Example: routers P,Q,R,SP,Q,R,S with links PQPQ, PRPR, QRQR, RSRS give A=(0110101011010010)\mathbf{A}=\begin{pmatrix} 0 & 1 & 1 & 0 \\ 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} Each row sum is the degree of that vertex; for a directed graph a row sum is the out-degree and a column sum is the in-degree.

Key termsadjacency matrixsymmetric
Common mistake

Putting 1s on the leading diagonal of a simple graph. A 1 there would mean a loop.

Section 2

Walks and powers of the matrix

A walk is a sequence of edges in which each edge starts where the previous one ends; edges and vertices may be repeated. Its length is the number of edges. The key result: the (i,j)(i,j) entry of Ak\mathbf{A}^k is the number of walks of length kk from vertex ii to vertex jj. Use your GDC to find the power. In the router example, A3\mathbf{A}^3 has (P,S)(P,S) entry 1, the single walk P→Q→R→SP\to Q\to R\to S, and A4\mathbf{A}^4 has (P,S)(P,S) entry 4. For a directed graph read the entry as walks from the row vertex to the column vertex.

Key termswalklength of a walk
Exam tip

For walks of length 3 you need A3\mathbf{A}^3, not 3A3\mathbf{A}. Use the matrix power on your GDC and read the correct row and column.

Section 3

Walks of at most a given length

To count walks of length at most kk between two vertices, add the matrices: A+A2+⋯+Ak\mathbf{A}+\mathbf{A}^2+\cdots+\mathbf{A}^k, and read the (i,j)(i,j) entry. Example: for the road network with B\mathbf{B} (villages W,X,Y,ZW,X,Y,Z), the (W,Z)(W,Z) entries of B\mathbf{B}, B2\mathbf{B}^2 and B3\mathbf{B}^3 are 00, 22 and 22, so there are 44 walks of length at most 3 from WW to ZZ. Walks of length 0 are not counted unless the question says so.

Key termswalks of length at most k
Common mistake

Reading only Ak\mathbf{A}^k when the question says 'at most kk'. You must add the lower powers.

Section 4

Weighted adjacency tables

For a weighted graph the table's entry in row ii, column jj is the weight of the edge from ii to jj (a cost, distance or time). Where there is no direct edge, write a dash, ∞\infty or sometimes 0, as the question states. For two-way roads the table is symmetric. Example: roads WX=12WX=12, WY=7WY=7, XY=5XY=5, XZ=9XZ=9, YZ=4YZ=4 give (–127–12–5975–4–94–)\begin{pmatrix} \text{–} & 12 & 7 & \text{–} \\ 12 & \text{–} & 5 & 9 \\ 7 & 5 & \text{–} & 4 \\ \text{–} & 9 & 4 & \text{–} \end{pmatrix} Powers of a weighted table do not count walks; to count walks use the unweighted matrix with 0s and 1s.

Key termsweighted adjacency table
Exam tip

Say what symbol you used for 'no direct road', and check that the table is symmetric for an undirected graph.

Section 5

Transition matrices

A transition matrix T\mathbf{T} describes moving between states with probabilities. In this course the entry in row ii, column jj is the probability of moving from jj to ii, so every column sums to 1. For a strongly connected graph, build T\mathbf{T} so that column jj shows the links leaving vertex jj (the transpose of a row-from adjacency matrix), then divide each column by its sum, so that each link from a vertex is equally likely. If s0\mathbf{s}_0 is the starting state, then sn=Tns0\mathbf{s}_n=\mathbf{T}^n\mathbf{s}_0. A steady state satisfies Ts=s\mathbf{T}\mathbf{s}=\mathbf{s} with entries summing to 1; this links to Markov chains (AHL 4.19). Example: pages AA to DD with A→B,CA\to B,C; B→CB\to C; C→A,DC\to A,D; D→AD\to A give T=(00121120001210000120)\mathbf{T}=\begin{pmatrix} 0 & 0 & \frac12 & 1 \\ \frac12 & 0 & 0 & 0 \\ \frac12 & 1 & 0 & 0 \\ 0 & 0 & \frac12 & 0 \end{pmatrix} Starting at AA, after 2 clicks the probabilities are (14,0,12,14)\left(\frac14,0,\frac12,\frac14\right).

Key termstransition matrixsteady statestrongly connected
Common mistake

Writing the probabilities along rows instead of columns. In this convention each column must sum to 1.

Section 6

PageRank

The Google PageRank algorithm treats web pages as vertices and links as directed edges. A surfer follows links at random, so the surfer's movement is described by a transition matrix. In the long run the probability of being on each page settles to the steady state, and the page rank is this probability: the larger it is, the more important the page. For the four pages above, solving Ts=s\mathbf{T}\mathbf{s}=\mathbf{s} gives s=(13,16,13,16)\mathbf{s}=\left(\frac13,\frac16,\frac13,\frac16\right), so pages AA and CC rank highest. If a page adds a new link, the probabilities in its column are shared among more pages: if DD linked to both AA and BB, column DD would become (12,12,0,0)T\left(\frac12,\frac12,0,0\right)^T.

Key termsPageRanksteady state vector
Exam tip

On the GDC, solve Ts=s\mathbf{T}\mathbf{s}=\mathbf{s} together with 'entries sum to 1', or apply a high power of T\mathbf{T} to a starting vector.

That's the notes covered.

Carry on to the next subtopic.

Exam questions on 3.15 Adjacency matrices and walks

  1. A network has four routers PP, QQ, RR and SS. The links are PQPQ, PRPR, QRQR and RSRS, and each link works in both directions. The network is modelled as a graph with the routers as vertices and the links as edges. Let A\mathbf{A} be its adjacency matrix with rows and columns in the order PP, QQ, RR, SS.
    Use your GDC to find the number of walks of length 4 from PP to SS.2 marks
  2. A delivery company has four hubs AA, BB, CC and DD with one-way routes A→BA\to B, B→CB\to C, C→AC\to A, C→DC\to D and D→BD\to B. This is modelled as a directed graph. Let M\mathbf{M} be its adjacency matrix, where the entry in row ii, column jj is the number of routes from hub ii to hub jj, in the order AA, BB, CC, DD.
    Use your GDC to find the number of walks of length 5 from DD to CC.2 marks
  3. Four villages WW, XX, YY and ZZ are joined by two-way roads, with distances in km: WXWX is 12, WYWY is 7, XYXY is 5, XZXZ is 9 and YZYZ is 4. There are no other roads.
    Write down the weighted adjacency table for the villages, in the order WW, XX, YY, ZZ, using –\text{–} where there is no direct road.3 marks
See the full worksheet

Written by the Exaim team, led by Shaun Daswani (Head of Upper Secondary, Improve ME Institute; MSc Financial Mathematics, Imperial College London; BSc, UCL) and Jason Daswani (operational lead, Improve ME Institute; LSE).