In simple terms
A friendly intro before the formal notes — no formulas yet.
From Networks to Numbers
A graph is just dots joined by lines: dots (vertices) are the things, lines (edges) are the connections. An adjacency matrix is a grid that records who connects to whom with a 1 or a 0. The magic is that multiplying that grid by itself counts routes: the entries of tell you how many ways there are to travel between any two dots in exactly steps.
Picture the direct-flight map of an airline. Writing '1' whenever there is a direct flight and '0' otherwise builds a grid. If a passenger wants a two-leg trip, one connection, you could trace every possibility by hand, but that is slow and error-prone. Instead, squaring the grid instantly reports, for every pair of cities at once, how many two-leg routes exist. Cube it and you get every three-leg route. The calculator turns a counting puzzle into a single multiplication.
- 1
Draw or read the graph: identify the vertices and the edges, and whether the edges have a direction (one-way) or a weight (a cost or distance).
- 2
Build the adjacency matrix : for an -vertex graph make an grid, putting the number of edges from vertex to vertex in position . For a simple graph every entry is 0 or 1.
- 3
Raise it to a power on the GDC: entering and computing , , is a calculator skill, far too slip-prone to do by hand under exam pressure.
- 4
Read the right entry: the number in row , column of is the number of walks of length from vertex to vertex . A diagonal entry counts closed walks that return home.
Explore the concept
Use the live diagram, PhET or GeoGebra sim, and synced steps — play it, drag controls, or tap a step.
Step 1
Draw or read the graph: identify the vertices and the edges, and whether the edges have a direction (one-way) or a weight (a cost or distance).
Key formulas
Tap any symbol to reveal exactly what it means and its units.
Full topic notes
Formal explanation with the rigour you need for the exam.
The language of graph theory
A graph is a set of vertices (also called nodes) together with a set of edges, each edge joining a pair of vertices. That is all a graph is; everything else is vocabulary for describing shapes and behaviour. The degree of a vertex is the number of edge-ends meeting there, which for a simple graph is just the number of edges attached to it. Edges may carry extra information: in a directed graph each edge has a direction, like a one-way street, so travel is only permitted along the arrow; in a weighted graph each edge carries a number such as a distance, time or cost.
A simple graph is undirected and unweighted, with no loops (an edge from a vertex to itself) and no repeated edges between the same pair of vertices; this is the commonest case in AI HL. A graph is connected when there is a walk between every pair of vertices, so the whole network hangs together in one piece. A subgraph is any graph you obtain by keeping some of the vertices and some of the edges of a larger graph. A tree is a connected graph with no cycles; a tree on vertices has exactly edges, which is why trees are the leanest way to keep a network connected.
Vertices and edges are the two ingredients of every graph; the degree of a vertex counts the edges meeting it (a loop counts twice).
Directed edges have arrows; weighted edges carry a number. A simple graph is undirected, unweighted, loop-free and has no repeated edges.
Connected means every pair of vertices is joined by a walk; a subgraph uses part of a graph; a tree is a connected, cycle-free graph with edges on vertices.
The adjacency matrix
The adjacency matrix of a graph with vertices is the matrix whose entry records the number of edges from vertex to vertex . Label the rows and the columns with the vertices in the same order, then fill each cell. For a simple graph every entry is 0 or 1: a 1 where an edge exists and a 0 where it does not. The matrix is a complete, machine-readable copy of the graph, and its shape reveals the graph's nature at a glance.
For a graph with adjacency matrix , the entry is the number of edges directly joining vertex to vertex , i.e. the number of walks of length 1 from to .
(or the number of edges) when vertices and are joined; when they are not.
For an undirected graph is symmetric: , because an edge between and is also an edge between and .
The main diagonal records loops: means a loop at vertex , so a simple graph has a zero diagonal.
The degree of a vertex in a simple undirected graph is the sum of its row (equivalently its column).
Walks and powers of the adjacency matrix
A walk is a journey along the edges of a graph in which vertices and edges may be repeated; its length is the number of edges it uses. The adjacency matrix already counts walks of length 1, since is the number of direct edges from to . The central result of the topic extends this to any length: raising to the power counts walks of length . The reason is exactly how matrix multiplication works. The entry of is , a sum over every possible middle vertex ; each term counts the ways to step from to and then from to , so the total is the number of two-step routes from to . Repeating the argument gives every higher power.
The number of walks of length from vertex to vertex is the entry of :
Two consequences are worth stating outright. A diagonal entry counts the closed walks of length that start and finish at vertex . And to count walks of length at most you sum the powers: the relevant entry of . Reading the wording of the question, an exact length or an at-most length, decides which matrix you need.
You are never expected to compute or higher by hand in the exam; it is a GDC skill. But you must show the set-up: state which matrix you entered, quote the powered matrix from your calculator, and point to the exact entry you read, row , column . That written trail is what the method marks are attached to.
Weighted (cost) matrices
When edges carry numbers, a distance, a time, a price, the graph is stored in a weighted matrix, also called a cost matrix. Its entry is the weight of the edge from to ; where there is no direct edge the cell is left blank or marked with a dash (sometimes ), and the diagonal is usually 0. The crucial distinction from the adjacency matrix is this: to find the cost of a route you add the weights of the edges along it; you do not take powers of the cost matrix. Powers count walks only when the entries are 0s and 1s.
Using the GDC for matrix powers
Every power in this topic should come from your calculator. Enter the matrix once into the matrix editor, giving it a name such as , then compute , and so on directly from the home screen, or form sums like in one expression for an at-most-length question. Type the entries carefully, keep the vertex order identical to the one you are reading answers against, and copy the powered matrix onto your script before extracting the single entry you need. Because the arithmetic is exact (the entries are whole numbers), there is no rounding to worry about, only accurate entry and the right choice of entry to read.
Two GDC habits save marks. First, re-check the matrix you typed against the graph before powering, since one mis-typed edge corrupts every entry of . Second, keep the same vertex ordering throughout; reading the entry only means 'vertex 2 to vertex 3' if your rows and columns are in that order.
Common mistakes examiners penalise
Using instead of - the number of walks of length is the entry of the matrix POWER , not of or times an entry. Multiplying a matrix by is not the same as raising it to the power .
Confusing degree with a diagonal entry - the degree of a vertex is the sum of its row (the edges meeting it), not the number sitting on the diagonal. In a simple graph the diagonal is all zeros.
Forgetting a directed graph is not symmetric - for a digraph an edge does not give an edge , so do not 'symmetrise' the matrix by reflecting entries. Copy the arrows exactly.
Misreading loops - a non-zero diagonal entry is a loop at vertex , and it adds 2 to that vertex's degree. Do not treat it as an ordinary edge to another vertex.
Powering a weighted matrix to count walks - powers count walks only for a 0/1 adjacency matrix. For a weighted graph, add weights along the route; do not raise the cost matrix to a power.
Answering the wrong length - 'walks of length exactly 3' needs , while 'walks of length at most 3' needs . Read the wording and pick the matrix to match.
Reading the wrong entry - keep a fixed vertex order; the entry means 'from vertex to vertex ' only if rows and columns follow that order, and swapping them silently loses the mark.
Model answer - marked the way our engine marks it
On Paper 2 the marks are analytic: each is tied to a specific line of working, a method mark (M) for the right approach or an accuracy mark (A) for a correct result, and an accuracy mark depends on the method mark it follows. Follow-through (FT) means an earlier slip need not cost you the marks that build on it, provided the later step is carried out correctly on your own figures, so a candidate who computes with one wrong entry but then reads the correct position still earns the reading mark. The engine also accepts any equivalent correct form. That protection exists only if the method is written down. Study how each of the four marks below is earned by a specific line.
Where this leads
Adjacency matrices are the gateway to the rest of the graph-theory topic. The same 0/1 matrix, weighted with distances, feeds the shortest-path and minimum-spanning-tree algorithms of 3.8, where trees reappear as the cheapest way to connect a network. The idea that a matrix can be multiplied to advance a system by one step returns in transition matrices and Markov chains, where powers of a matrix push a probability distribution forward in time. Master the two moves here, translating a graph into a matrix and reading walks off its powers, and you have the core technique that the more advanced network mathematics is built upon.
Worked examples
See the formulas applied — reveal one step at a time, like the exam.
A simple undirected graph has vertices and edges , , , , and . (a) Construct the adjacency matrix , ordering the vertices . (b) Write down the degree of vertex . (c) State, with a reason, whether the graph is connected. [6]
- 1
(a) Adjacency matrix. Build a grid, rows and columns in the order , and place a 1 wherever an edge is listed. [M1: correct size, labelled, 0/1 entries]
A directed graph on vertices has adjacency matrix . Find the number of walks of length 3 that start and end at vertex 2. [4]
- 1
A closed walk of length 3 from vertex 2 to itself is counted by the diagonal entry .
Four towns are joined by roads with the following lengths (in km): , , , . There is no direct road or . (a) Write down the cost matrix, ordering the towns and using a dash for a missing road. (b) Find the length of the route , and state why powering this matrix would not count that route. [5]
- 1
(a) Cost matrix. Place each road length symmetrically (the roads are two-way), 0 on the diagonal and a dash where no road exists. [M1: symmetric set-up with weights]
A graph has adjacency matrix . Find the number of walks of length 2 from vertex 1 to vertex 2. [4]
- 1
Model answer - full working. \nThe number of walks of length 2 from vertex 1 to vertex 2 is the entry of .
How it all connects
The big idea sits in the middle — tap a linked idea to explore the link.
Tap a linked idea to see how it connects back to the main topic — that connection is what examiners reward.
Glossary
Try to recall each definition before you reveal it.
Quick check
Answer in your head first — then tap to check. No pressure.
Revision flashcards
Flip the card. Test yourself before the exam.
Vertex and edge
A graph is a set of vertices (nodes) joined by edges. An edge connects a pair of vertices; it models a relationship or a link. The whole of graph theory is built from these two objects.
Key takeaways
Review these before you close the topic — retrieval beats re-reading.
- ✓
Vertices and edges are the two ingredients of every graph; the degree of a vertex counts the edges meeting it (a loop counts twice).
- ✓
Directed edges have arrows; weighted edges carry a number. A simple graph is undirected, unweighted, loop-free and has no repeated edges.
- ✓
Connected means every pair of vertices is joined by a walk; a subgraph uses part of a graph; a tree is a connected, cycle-free graph with edges on vertices.
Practice — then mark it
The whole point: a real Cambridge question, marked mark-by-mark.
Get a Paper 2 graph-theory question marked: build the adjacency matrix, power it and read the walks with full working
Get a Paper 2 graph-theory question marked: build the adjacency matrix, power it and read the walks with full working
Extra simulations & links
PhET, GeoGebra and other curated tools — open in a new tab.
Frequently asked
Checkpoint
One marked question is worth ten re-reads — close the loop before you move on.
Reading it isn’t knowing it — prove it.
Before you move on: do Get a Paper 2 graph-theory question marked: build the adjacency matrix, power it and read the walks with full working on paper, snap a photo, and get examiner-style feedback on exactly where you win and lose marks.