Write adjacency matrices for undirected and directed graphs, count walks of a given length with matrix powers, read weighted adjacency tables, and build the transition matrix of a random walk, as in Google's PageRank.
Each is in the Maths AI glossary, with every other term in the subject.
The square matrix of a graph with vertices in which the entry in row , column is the number of edges from vertex to vertex .
With a free account, Augment remembers where you stopped and what you have practiced.
A walk that starts and finishes at the same vertex.
In PageRank, the probability that at each step the random surfer follows a link from the current page; with probability the surfer instead jumps to a page chosen at random from the whole network.
The number of edges in the walk, counting each repeated edge every time it is used.
A method of ranking the pages of a network of hyperlinks by the long-run proportion of time a random surfer, following links at random (with occasional random jumps), spends on each page.
A process in which a walker moves from vertex to vertex along edges, at each step choosing one of the edges leaving the current vertex at random, all such edges being equally likely.
A square matrix that is unchanged when reflected in its leading diagonal, so the entry in row , column equals the entry in row , column for every and .
A sequence of edges in which each edge after the first starts at the vertex where the previous edge ends; vertices and edges may be repeated.
A table for a weighted graph with one row and one column for each vertex, in which each entry is the weight of the edge joining the two vertices, and a blank (or a dash) means there is no direct edge.
Write down the adjacency matrix of an undirected or directed graph, including loops and multiple edges, and draw a graph from its adjacency matrix.
Identify walks in a graph and state the length of a walk.
Find the number of walks of length between two vertices using the th power of the adjacency matrix.
Find the number of walks of length at most (or less than ) by adding powers of the adjacency matrix.
Find the number of closed walks of a given length from the diagonal of a power of the adjacency matrix.
Interpret entries of matrix powers in context, including zero entries.
Draw a weighted graph from a weighted adjacency table and use the table to answer questions about costs, distances or times.
Construct the transition matrix of a random walk on a strongly connected undirected or directed graph, and interpret its long-run behaviour, as in the PageRank algorithm.
A drawing of a graph is easy for a person to read, but a calculator or computer needs the same information in numerical form. To work with a network numerically, the graph is stored as a grid of numbers: one row and one column for each vertex, with each entry counting the edges between a pair of vertices. This grid is a matrix, so the matrix algebra of subtopic 1.14, Matrices, applies to it. Multiplying the matrix by itself counts routes through the network, and dividing its entries by the numbers of edges at each vertex turns it into a table of probabilities for a traveller moving at random.
These ideas are used every day. An airline's table of direct flights, squared, gives the number of one-stop connections between cities. A search engine models a person clicking links at random and ranks web pages by how often that person arrives at each one; this is the PageRank algorithm developed by Larry Page and Sergey Brin at Stanford University in 1996.
To store a graph with vertices, list the vertices in a fixed order and make an square matrix. Row and column both belong to the th vertex. The entry in row
The figure of graph G and its adjacency matrix shows five vertices, A to E, with six edges. Row A has 1s in columns B, C and D, because A is joined to exactly those three vertices, and 0s in columns A and E.

With rows and columns in the order A, B, C, D, E, the matrix is
Three properties follow from the way the matrix is built.
The leading diagonal is all zeros when the graph has no loops, because no vertex is joined to itself.
Each row sum is the degree of that vertex (for a graph without loops): row A adds to 3, and A has degree 3. The column sums give the same numbers.
The matrix is symmetric. An edge joining A and B also joins B and A, so the entry in row A, column B equals the entry in row B, column A.
Symmetry gives a quick check on a matrix written down in a hurry: any entry that does not match its mirror image across the diagonal is an error. It also means that for an undirected graph the total of all the entries is twice the number of edges, which is the degree-sum fact of subtopic 3.14 in matrix form.
Two kinds of edge from subtopic 3.14 need a rule. Multiple edges simply give entries greater than 1: if two separate edges join vertices J and K, the entries in positions (J, K) and (K, J) are both 2. A loop at a vertex adds 1 to the diagonal entry for that vertex.
The loop convention matters for counting walks: a loop is one edge, and using it once moves a walker one step along the graph while staying at the same vertex. A diagonal entry of 1 therefore means "one way to step from this vertex to itself".
In a directed graph an edge from P to Q does not give an edge from Q to P, so the matrix needs a convention about direction. The standard convention is
so rows are "from" and columns are "to". A directed graph's adjacency matrix is usually not symmetric. Each row sum is the out-degree of that vertex, and each column sum is its in-degree.

A walk is a journey through a graph along its edges, with each edge starting at the vertex where the last one finished. Nothing forbids going back along the same edge or visiting a vertex twice: A → B → A → C is a walk in graph G.
Walks are the most general kind of route. Subtopic 3.16 introduces more restricted kinds: a trail repeats no edge, a path repeats no vertex, and closed versions of these are circuits and cycles. Every trail and every path is a walk, but most walks are neither.
The length is the number of steps taken. A walk of length lists vertices, because the starting vertex has to be written down before any step is taken.
In graph G, the walks of length 2 from A to C go through a middle vertex that is adjacent to both A and C. A is adjacent to B, C and D, and C is adjacent to A, B and D, so the possible middle vertices are B and D. There are exactly two walks of length 2 from A to C: A–B–C and A–D–C.
Listing by hand works for very short walks, but the number of walks grows quickly. Graph G has 6 walks of length 4 from A to E and 10 walks of length 5 from A to E, and listing them all is slow and error-prone. Matrix multiplication counts them systematically.
A walk of length 2 from vertex to vertex has the form for some middle vertex . The number of ways to make the first step is the entry
The right-hand side is exactly how an entry of a product is formed in matrix multiplication: row of the first matrix times column of the second. So the entry in row , column of is the number of walks of length 2 from

When there are multiple edges, the products count the different choices of edge at each step. In the Königsberg graph two bridges join the island A to bank B and two join A to bank C, so a walk B → A → C can be made in ways, by choosing one bridge for each step.
The same argument extends one step at a time. A walk of length 3 from to is a walk of length 2 from to some vertex , followed by one edge from to . The number of such walks is the sum over
The result holds for undirected and directed graphs, with loops and multiple edges, provided the adjacency matrix follows the conventions for loops, multiple edges and directions. For a directed graph the walks must follow the arrows, and the rows-from, columns-to convention makes the multiplication count them correctly.
For graph G the first few powers are
The entry 2 in row A, column C of matches the two walks A–B–C and A–D–C found by hand. The entry 6 in row A, column E of says that there are six walks of length 4 from A to E.
Powers of a matrix larger than are found with the GDC.
Open the matrix editor and define a matrix of the right order (for graph G, ). On a TI-84 Plus CE the matrix menu is 2nd x⁻¹ (MATRIX), then EDIT; on a Casio fx-CG50 matrices are entered in the Run-Matrix application.
Type the entries row by row, in the vertex order chosen.
On the calculation screen, raise the matrix to the required power, for example [A]^4, and read the entry in the required row and column.
What to write down: the adjacency matrix (with its row and column labels if the order is not the one given), the power calculated (""), and the entry used, for example "entry (A, E) of is 6". The whole of need not be copied out; the row or entry used is enough.
The diagonal entries of count closed walks: entry (, ) is the number of walks of length from vertex back to vertex
Two special cases are worth knowing.
In a simple undirected graph, the diagonal of gives the degrees. A closed walk of length 2 from goes out along one edge and straight back, and there is one such walk for each edge at . In graph G the diagonal of is 3, 2, 3, 3, 1, the degrees of A to E. (With multiple edges this fails: going out along one bridge and back along the other also counts.)
In a simple undirected graph, a closed walk of length 3 goes round a triangle. Each triangle gives 6 closed walks (3 starting vertices × 2 directions). Graph G has two triangles, ABC and ACD, and
A question may ask for walks of length at most (or "no more than steps"), or less than . These include walks of every length up to the limit, so the matrices for each length are added.
On the GDC, type the sum directly, for example [A]+[A]^2+[A]^3+[A]^4, and read the entry. A walk of length 0 (staying put) is not normally counted, so the sum starts at , not at the identity matrix.
An entry of equal to 0 means there is no walk of length exactly between those two vertices. It does not mean the vertices are disconnected: a walk of a different length may exist. In graph G, entry (A, E) of is 0 but entry (A, E) of is 1.
The first power for which entry (, ) becomes non-zero is the smallest number of edges needed to get from to . For A and E in graph G it is 2. If an entry of
A small change to the matrix tracks spreading processes. If every vertex is given a loop (a 1 on every diagonal entry), then a walker can "wait" at a vertex for a step. Entry (, ) of the th power of this matrix is then non-zero exactly when can be reached from in at most steps. This models anything that, once it arrives, stays: pollution in a water network, a rumour, or an infection.

The number of walks counts sequences of steps, and the same place or person can appear in many of them. This affects how results are interpreted.
In a friendship network (an undirected simple graph of who is friends with whom), entry (, ) of , for
A weighted graph carries a number on each edge: a distance, a cost or a time. Its table form is laid out like an adjacency matrix, with each entry recording the weight of the edge in place of the number of edges.
A blank in a weighted table means "no edge". It must not be read as 0, which would mean an edge costing nothing. For an undirected graph the table is symmetric; for a directed graph rows are "from" and columns are "to", and the cost from X to Y can differ from the cost from Y to X.
From \ To | W | X | Y | Z |
|---|---|---|---|---|
W | 120 | 200 | ||
X | 110 | 90 | ||
Y | 210 | 150 | ||
Z | 180 | 140 |
Costs in US dollars of direct flights between four cities (hypothetical). Rows are departure cities, columns are destinations; a blank means no direct flight.
Weighted tables are the input to the network algorithms of subtopic 3.16: Prim's algorithm has a version that works directly on the table, and the travelling salesman problem starts from a table of least distances.
Suppose a walker moves around a graph one step at a time and, at each vertex, chooses one of the edges leaving it at random, each equally likely. The walker's position after each step is uncertain, but the probabilities of being at each vertex can be calculated. This model is called a random walk on the graph.
If vertex has out-degree (its degree, for an undirected graph), each edge leaving is chosen with probability
The probabilities are collected in a transition matrix , using the convention of subtopic 4.19, Transition matrices and Markov chains: columns are "from" and rows are "to", so
and each column of adds up to 1. The probabilities of being at each vertex after steps form a column vector , with
The construction from the adjacency matrix depends on the type of graph.
Undirected graph. is symmetric, so column of lists the edges at vertex . Divide each column of by the degree of its vertex.
Directed graph. Row
In both cases a quick check is that every column adds to 1.
As the number of steps grows, usually settles down to a fixed vector, the steady state, which gives the long-run proportion of time the walker spends at each vertex. On the GDC it is estimated by calculating for a large
For graph G, starting anywhere, gives
These are the degrees 3, 2, 3, 3, 1 divided by their sum, 12. This is true for every connected undirected graph whose random walk settles down: in the long run a random walker visits each vertex in proportion to its degree, because a vertex with more edges has more ways in.
The graph needs to be strongly connected (for an undirected graph, connected) for the long run to make sense for the whole network. If some vertex cannot be reached from another, the walker's long-run position depends on where it started. If a vertex has out-degree 0, the walker gets stuck there, and its column of cannot be filled in at all, since there is nothing to divide by. A strongly connected graph guarantees a single steady state that does not depend on the start. On some strongly connected graphs, such as a single directed cycle, keeps cycling and never settles; subtopic 4.19 explains which chains, the regular ones, always settle.
A search engine has to decide which of thousands of matching pages to show first. The idea behind PageRank is that a link from one page to another is a vote of confidence, and that votes from important pages should count for more. Page and Brin turned this into a random walk: a "random surfer" starts on some page and keeps clicking links chosen at random. Pages that the surfer visits often in the long run are ranked highly.
The web is modelled as a directed graph: each page is a vertex and each hyperlink is an edge from the page containing the link to the page it points to. The transition matrix is built exactly as for any directed graph, and the PageRank of each page is its entry in the steady state vector.

The real web is not strongly connected. Some pages have no outgoing links, and some groups of pages link only to each other, so a surfer who only follows links would get stuck. PageRank solves this by letting the surfer sometimes jump to a completely random page.
With pages, the surfer moves from page to page with probability (following a link) plus
where is the matrix of 1s. Every entry of is positive, so the surfer can get from any page to any other in one step: the modified graph is strongly connected, and a single long-run vector always exists.
YouTubeThe seven bridges of Königsberg, analysed by Leonhard Euler in 1736, joined four land masses: the island A, the two river banks B and C, and the eastern land D. Two bridges joined A to B, two joined A to C, and one bridge each joined A to D, B to D and C to D (subtopic 3.14 draws the graph). Because of the double bridges, the adjacency matrix has entries of 2.
Bridges from Euler's 1736 figure (Wikipedia, "Seven Bridges of Königsberg", 2026); matrix powers calculated.
Two-bridge strolls. Entry (B, C) of is 5. A walker going from bank B to bank C across exactly two bridges can cross to the island and then to C, choosing one of 2 bridges each time ( ways), or cross to D and then to C (
Out and back. The diagonal of is 9, 5, 5, 3, not the degrees 5, 3, 3, 3. From the island there are 5 bridges out, and a walker who leaves by one of the two bridges to B can come back by either of them. Adding the squares of the entries in row A counts the out-and-back strolls:
The rule "diagonal of = degree" holds only for simple graphs.
Three-bridge strolls. Entry (A, A) of is 8: there are 8 ways to leave the island and return to it after crossing exactly three bridges, each going round a triangle such as A–B–D–A (2 choices of bridge to B, 1 each for the other two, in either direction).
A random stroller. A visitor crosses a bridge chosen at random from those at the current land mass, each equally likely. Dividing each column of by the number of bridges at that land mass (5, 3, 3, 3) gives the transition matrix.
From the island, the visitor reaches bank B with probability , because 2 of its 5 bridges lead there. Raising to a high power (
the numbers of bridges at each land mass divided by the 14 bridge-ends. In the long run the stroller arrives on the island on about 36% of crossings, because it has 5 of the 14 bridge-ends.
What the model leaves out. The model assumes each bridge is equally likely to be chosen and ignores distances and the time spent on each land mass. One matrix holds the whole bridge structure of the city, and its row sums are the degrees. Euler's question, whether a walk can cross every bridge exactly once, depends only on those degrees and is answered in subtopic 3.16.
Adjacency matrices appear on HL Papers 1, 2 and 3, usually for 2–6 marks inside a network question. The recurring shapes are: write down the adjacency matrix of a drawn graph or table (often with a loop, multiple edges or directed edges), find the number of walks of a given length between two vertices or back to the start, find the number of walks of at most a given length, determine when something spreading through a network first reaches a vertex, and construct a transition matrix for a random walk, then use a high power for the long run. The formula booklet has no formulas for adjacency matrices or walks.
GDC working to write down: the matrix entered (with row and column labels if the order is not given), the power used (""), and the entry or entries read. For a trace question the diagonal entries are enough. For a transition matrix, write the matrix and the power used, for example "".
A frequent loss of marks is an entry read from the wrong power or from a matrix with rows and columns swapped. Before reading any entry, check the matrix against two or three edges of the graph, and write the length of walk next to the power used.
Questions about spreading or reachability are answered best with a short table of the relevant row of each power, showing where each entry changes from zero to non-zero. Examiners have reported that candidates often calculate the powers correctly but cannot say what a zero entry means: it means no walk of exactly that length.
A graph has vertices A, B, C and D, with edges AB, AC, BC and CD and a loop at D. Write down its adjacency matrix. [2]
An undirected graph has adjacency matrix
The adjacency matrix of a graph has entry (, ) equal to the number of edges from vertex to vertex ; a loop adds 1 to the diagonal and multiple edges give entries above 1.
An undirected graph has a symmetric adjacency matrix whose row sums are the degrees (when there are no loops). For a directed graph rows are "from" and columns are "to": row sums are out-degrees and column sums are in-degrees.
A walk is a sequence of edges, each starting where the last ended, with repeats allowed; its length is the number of edges.
Entry (,
I can write down the adjacency matrix of an undirected graph, including loops and multiple edges.
I can write down the adjacency matrix of a directed graph with rows as "from" and columns as "to", labelling them.
I can draw a graph from its adjacency matrix and find degrees, allowing for loops.
I can explain why the adjacency matrix of an undirected graph is symmetric.
I can find the length of a walk and tell a closed walk from an open one.
I can explain why entry (, ) of
36 exam-style questions on this subtopic, written in the style of the IB papers. The first has its markscheme open. Counted on
A ferry company serves five islands: Arlo (A), Brae (B), Cove (C), Dunn (D) and Eske (E). Ferries run in both directions on each of the following direct routes, and there are no other direct routes.
A–B, A–C, B–C, B–D, B–E, C–E, D–E
The adjacency matrix of this network has rows and columns in the order A, B, C, D, E.
Write down .
2 marks
A2
Note: Award one mark for a symmetric matrix with zeros on the leading diagonal and at most two errors.
[2 marks]
Explain why is equal to its transpose (it is symmetric about its leading diagonal).
1 mark
every route runs in both directions, so the number of direct routes from X to Y equals the number from Y to X R1
[1 mark]
Find .
2 marks
Interpret the element in row 2, column 2 of in context.
1 mark
there are 4 ways to start at Brae, make exactly two ferry journeys and finish back at Brae A1
[1 mark]
Find the number of ways of travelling from Arlo to Eske using exactly three ferry journeys.
2 marks
row 1, column 5 of (M1)
A1
[2 marks]
Find the total number of ways of making exactly four ferry journeys that start and finish at the same island.
2 marks
sum of the leading diagonal of :
Find the number of ways of travelling from Arlo to Dunn using at most three ferry journeys.
3 marks
(M1)
row 1, column 4:
Explain why your answer to part (g) may be more than the number of sensible routes a passenger would take.
1 mark
the count includes walks that revisit an island (e.g. A–B–A–... or B–C–B), which a passenger would not choose R1
[1 mark]
A farm has six water storage tanks, , , , , and
A museum has six galleries, , , , , and
The adjacency matrix of every undirected graph is symmetric.
with rows and columns in the order J, K, L, M.
(a) Draw the graph.
(b) Find the degree of each vertex and the number of edges.
(a) Work through the entries on and above the leading diagonal only, since the matrix is symmetric.
Row J: the 1 in column J is a loop at J; the 2 in column K means two edges J–K; the 1 in column M means one edge J–M.
Row K: the 1 in column L means one edge K–L; the 1 in column M means one edge K–M.
Row L: the 2 in column M means two edges L–M.
Draw four vertices, a loop at J, two separate (curved) edges between J and K, two between L and M, and single edges J–M, K–L and K–M.
(b) The loop adds 2 to the degree of J, so , one more than the row sum of 4. The other vertices have no loops, so their degrees are their row sums: , , .
The sum of the degrees is , so the graph has edges: the loop, J–K twice, J–M, K–L, K–M and L–M twice.
(b) The out-degree of P is the sum of row P: (the street P → Q). The in-degree of P is the sum of column P: (the streets R → P and T → P).
The entry in row D, column A is 6, so there are 6 walks of length 3 from D to A. (For example D–E–D–A, D–C–B–A and D–A–C–A.)
(b) Calculate ; its entry in row A, column E is 10, so there are 10 walks of length 5 from A to E.
(c) E is adjacent only to D, so any walk leaving E goes to D, and any walk arriving at E comes from D. A closed walk of length 3 from E would be E–D–X–E, which needs X adjacent to E, so X = D; but D is not joined to itself. No closed walk of length 3 starts at E, which is what the 0 says: E does not lie on any triangle of the graph.
The diagonal entries are 2, 3, 1, 2 and 2, so the total number of closed walks of length 4 is
(b) This is entry (Q, Q) of : 3 ways. Listing them confirms the count: Q–S–Q–S–Q, Q–R–T–P–Q and Q–S–T–P–Q. Each follows the arrows and uses exactly 4 streets.
There are 8 walks of length at most 4 from A to E. On the GDC, entry (A, E) of is 8.
(b) Less than 4 means lengths 1, 2 and 3: walks (A–D–E and A–C–D–E).
Only row U matters, because the spill starts at U. From the GDC:
Power | Row U (columns U, V, W, X, Y, Z) | Towns polluted |
|---|---|---|
1, 1, 0, 0, 0, 0 | U, V | |
2, 2, 1, 0, 0, 1 | U, V, W, Z | |
4, 6, 3, 2, 0, 3 | U, V, W, X, Z | |
10, 16, 11, 8, 2, 11 | all six |
Entry (U, Y) is 0 in and non-zero in , so Y is polluted last, after 4 days. Only the zero or non-zero pattern matters here; the sizes of the numbers count walks and have no meaning for the pollution.
In an airline network of direct flights, counts one-stop connections and two-stop connections. The diagonal of counts round trips of exactly six flights, but many of them fly back and forth along the same route.
A walk may repeat vertices, so "number of walks of length 6 from A to A" is not the number of ways to visit six different places. A trip that visits every city exactly once is a cycle, studied in subtopic 3.16.
(a) With
(b) Entry (B, E) is 2: Ben and Eva are not friends, but they have 2 mutual friends (Chloé and Dev). Entry (B, B) is 3: Ben has 3 friends (Ana, Chloé and Dev), since each friendship gives one walk out and back.
(c) Entry (B, D) is 0: Ben and Dev are friends, but they have no mutual friends. The 0 does not mean they are unconnected; it means no walk of length exactly 2 joins them.
(c) The cheapest way back from Z to W is the direct flight, US$180 (Z → Y → W would cost ). The cheapest round trip is W → X → Z → W, costing
Each column adds to 1. Column E has a single 1 in row D, because the only edge at E leads to D.
(b) Start with (certainly at E). On the GDC:
The probability of being at D after 3 steps is . (The walker goes E → D first; from D it can return to E and come straight back, or go to A or C and come back to D.)
Each column adds to 1. The graph is strongly connected, since A → B → C → D → A visits every page.
(b) Start with and calculate on the GDC for large :
1 | 2 | 3 | 10 | 50 | |
|---|---|---|---|---|---|
A | 0.375 | 0.3125 | 0.344 | 0.333 | 0.333 |
B | 0.125 | 0.1875 | 0.156 | 0.167 | 0.167 |
C | 0.375 | 0.3125 | 0.344 | 0.333 | 0.333 |
D | 0.125 | 0.1875 | 0.156 | 0.167 | 0.167 |
The long-run proportions are A , B , C , D . Pages A and C rank equal first, and B and D equal third. A receives links from two pages, C and D, and D passes on everything it receives; C also receives links from two pages, A and B.
Check: for , since for example the first row gives .
(b) Find the PageRank of each page, correct to 3 significant figures.
(a) Every entry of is multiplied by 0.85, then is added to every entry.
Each column still adds to 1: for example .
(b) On the GDC, with
The PageRanks are A 0.325, B 0.175, C 0.325, D 0.175. The ranking is unchanged, but the random jumps move some probability from the popular pages A and C towards B and D, so the scores are less extreme than and .
A2
Award A1 for one error. Accept the transpose if its orientation is made clear.
(b) calculating (M1)
entry (A, D) of is 2 A1
(c) (M1)
entry (C, D) is A1
(d) (M1)
A1
(e)
A2
Award A1 for a matrix with correct non-zero positions but one incorrect probability, or for the transposed matrix with rows adding to 1.
(f) calculating a high power of , for example (M1)
A1
Total [12]
A directed graph has edges V → W, W → X, X → V, X → Y, Y → Z, Z → X and W → Z. (a) Write down its adjacency matrix. (b) Find the number of walks of length 4 from W to X. (c) Find the total number of closed walks of length 3. [5]
For the graph in question 3, find the number of walks from V to X of length at most 3, and list them. [3]
Explain why, in a simple undirected graph, the diagonal entries of are the degrees of the vertices. [2]
Four villages are joined by roads of lengths (in km) P–Q 6, P–R 9, Q–R 4, R–S 5. Write down the weighted adjacency table, and find the shortest distance by road from P to S. [3]
A walker moves at random on the graph with vertices P, Q, R, S and edges PQ, PR, QR, RS. (a) Construct the transition matrix. (b) The walker starts at S. Find the probability that the walker is at S after 2 steps. (c) Write down the long-run proportion of time spent at R. [5]
Three web pages X, Y and Z have links X → Y, Y → X, Y → Z and Z → X. (a) Construct the transition matrix of a random surfer. (b) Find the PageRank of each page without damping, as exact fractions. [4]
Five towns are linked by pipes 1–2, 2–3, 2–4 and 4–5, and a leak at town 3 spreads along one pipe per day, with polluted towns staying polluted. Find which town is polluted last and on which day, showing the relevant rows of matrix powers. [4]
A web of pages contains a page with no outgoing links. Explain why the transition matrix of the random surfer cannot be constructed without modification, and describe how a damping factor solves the problem. [3]
(a) Sum of entries , so edges. (b) Entry (B, C) of is 15.
(a) Rows V, W, X, Y, Z: , , , , . (b) Entry (W, X) of is 2. (c) .
Entry (V, X) of is : V–W–X and V–W–Z–X.
Entry of is ; in a simple graph each is 0 or 1, so this is the number of 1s in row , which is the degree of (each closed walk of length 2 goes out along one edge and back along it).
Symmetric table with entries PQ 6, PR 9, QR 4, RS 5 and blanks elsewhere. P to S: P–R–S km and P–Q–R–S km, so the shortest distance is 14 km.
(a) Degrees P 2, Q 2, R 3, S 1. Columns P, Q, R, S: , , , . (b) S → R (probability 1), then R → S with probability : . (c) (degree 3 out of degree sum 8).
(a) Columns X, Y, Z: , , . (b) X , Y , Z .
Matrix with 1s on the diagonal; row 3 of : towns 2, 3; of : towns 1, 2, 3, 4; of : all five. Town 5 is polluted last, on day 3 (entry (3, 5) is 0 in and 1 in ).
The column for that page would need dividing by its out-degree, which is 0, so its column cannot add to 1 (the surfer is stuck). With damping, the surfer jumps to a random page with probability at each step (and from a page with no links is usually sent to a random page), so every column of the modified matrix adds to 1 and every page can reach every other.
Walks of length at most come from ; the trace of counts closed walks of length .
A zero entry in means no walk of exactly length . With 1s added on the diagonal, the first power with a non-zero entry gives the number of steps needed to reach a vertex.
A weighted adjacency table records the weights of edges, with blanks for missing edges; its powers have no meaning.
The transition matrix of a random walk has , columns adding to 1; high powers of give the long-run proportions, which for a connected undirected graph are proportional to the degrees.
PageRank ranks web pages by the long-run proportions of a random surfer on a strongly connected link graph, made so by a damping factor (about 0.85) with random jumps.
I can use the GDC to find the number of walks of length between two vertices.
I can find the number of walks of length at most or less than by adding powers.
I can find the total number of closed walks of length from the trace of .
I can interpret a zero entry in a power of an adjacency matrix and use powers to find when a vertex is first reached.
I can interpret walk counts in context, such as mutual friends or one-stop flights.
I can read a weighted adjacency table, including blanks and different costs in each direction.
I can construct the transition matrix of a random walk on an undirected or directed graph, with columns adding to 1.
I can estimate long-run proportions with a high power of the transition matrix and explain why the graph must be strongly connected.
I can explain how the damping factor in PageRank works.
Note: Follow through from their .
[2 marks]
A1
[2 marks]
A1
[3 marks]
– | 34 | 51 | 28 | 46 | 60 | |
34 | – | 25 | 39 | 57 | 44 | |
51 | 25 | – | 48 | 31 | 37 | |
28 | 39 | 48 | – | 42 | 53 | |
46 | 57 | 31 | 42 | – | 35 | |
60 | 44 | 37 | 53 | 35 | – |
The farmer, Amaru, wants to connect all six tanks using the minimum total length of pipe.
Use Prim's algorithm, starting at , to find the minimum spanning tree. Show clearly the order in which the edges are selected.
4 marks
Find the minimum total length of pipe needed.
2 marks

Write down the adjacency matrix for the doorways, with rows and columns in the order to .
2 marks
Find the number of different ways of walking from gallery to gallery by passing through exactly three doorways.
2 marks
A security guard, Ines, wants to walk through every doorway exactly once. Explain why this is possible, and state the galleries in which she must start and finish.
3 marks
The following table shows the least walking times, in minutes, between the galleries. Find the values of , , and .
A tour guide starts at the entrance gallery , visits every gallery and returns to . Use the nearest neighbour algorithm on the table to find an upper bound for the walking time of the tour.
3 marks
By deleting vertex and using Prim's algorithm starting at , find a lower bound for the walking time of the tour.
4 marks
Let be the least walking time of the tour. Write down an inequality for .
1 mark
– | 4 | 6 |
4 | – | 3 | 5 | 8 | 10 |
6 | 3 | – | 4 | 7 |
5 | 4 | – | 3 | 5 |
8 | 7 | 3 | – | 4 |
10 | 5 | 4 | – |
2 marks