In this guide
← Maths AI guides

Geometry & trigonometry · AI HL

Graph theory, walks and adjacency matrices

Translate networks into graphs, distinguish route types and use adjacency matrices to count walks of a given length.

Course focus: AI HL · First-assessment-2021 course. The sections distinguish the mathematical idea, the calculation and its interpretation.

Before you start: Counting, matrices and interpretation of contextual networks.

Start with a small example

Build it from the beginning

HL content

A graph records objects as vertices and connections as edges. The drawing position usually does not affect the network. Distinguish a route visiting vertices from a route covering edges; these are different problems.

A first walkthrough

A graph has edges AB, BC and CA. State the vertex degrees and number of edges.

  1. Each of A, B and C touches two edges.
  2. The degree list is 2,2,2.
  3. The total degree is 6, twice the three edges because each edge has two ends.
Try the practice ladder after learning the methods ↓

The foundations behind the method

Understand what the symbols mean

A network graph records connections rather than geometric shape. Moving a vertex or bending an edge leaves the abstract graph unchanged unless distances are encoded as weights. The important first step is choosing what vertices, edges and directions mean for the question being asked.

How the ideas connect

Adjacency matrices turn local connections into arithmetic. One multiplication combines successive moves through possible intermediate vertices. This explains why powers count walks and why repeated vertices are allowed: multiplication checks permitted moves, not a global condition that each vertex is used only once.

01

Start with the idea

Build your understanding

Abstraction

An edge crossing on a drawing is not a vertex unless the network definition makes it one.

Objective

Visiting each edge is an Euler question; visiting vertices once is a Hamiltonian question. The route requirements must be stated first.

Compare the approaches

Choose by the information in the question, rather than the formula you recognise first.

Adjacency powers

When it helpsUse them for counts of fixed-length walks.

Check before using itDo not interpret weighted costs under ordinary matrix powers as shortest-path distances.

Route algorithms

When it helpsChoose one for the stated coverage or minimisation problem.

Check before using itA locally cheapest move may fail a global objective unless the algorithm has the appropriate guarantee.

Your method plan

  1. Define graph type, ordering and edge meaning.
  2. Translate the requested route or count into the matching method.
  3. Verify the result against the original network constraints.
02

Learn the methods

Learn step by step

1. A graph is a network, not a function plot

A graph consists of vertices and edges describing relationships. Its drawing is a representation: edge lengths and crossing points do not matter unless weights or vertices are explicitly assigned. A vertex may represent a town, task or state; an edge may represent a road or allowed move. State whether edges are directed, whether loops or multiple edges are allowed, and what a weight means before applying an algorithm.

2. Degree and connectivity

The degree of an undirected vertex counts incident edge ends; a loop contributes two. Summing degrees counts each edge twice, giving the handshake relation. A connected undirected graph has a route between every pair of vertices. For directed graphs, distinguish in-degree and out-degree and be precise about which direction of reachability is intended. A network can appear connected in its drawing while directed travel is not possible between every pair.

Handshake relation

Why this formula works

Each edge has two ends, and each end is counted in a vertex degree. A loop contributes both ends at the same vertex. Summing degrees therefore counts exactly twice the number of edges, independently of how the graph is drawn or how its edges cross on the page.

The formula

\(\sum_v\deg(v)=2|E|\) for an undirected graph.

Quick example

Degrees 2, 3, 3, 2 sum to 10, so there are 5 edges. An odd degree sum would signal an impossible undirected degree list.

Worked example: Check a claimed network

A simple undirected network is said to have five vertices of degrees 1,2,2,2,2. Is this possible?

  1. The degree sum is 9.
  2. Every edge contributes two to that sum.
  3. Nine is odd, so the list cannot represent any undirected graph.
  4. This check disproves the claim without reconstructing the drawing; even sums alone would not guarantee a valid simple degree sequence.

3. Walk, trail, path and circuit

A walk can repeat vertices and edges. A trail does not repeat edges, and a path does not repeat vertices under the usual simple-path convention. A closed route starts and ends at the same vertex. Textbook terminology can vary, so use the definition supplied in the task. An Euler route focuses on using every edge; a Hamiltonian route focuses on visiting vertices. These are different constraints and can lead to different solutions on the same graph.

Different route requirements on one network

ABCD12346
The weighted network has four vertices and five undirected edges. The weights encode costs, not geometric lengths. A shortest path, a spanning tree, an edge-covering route and a vertex tour are different questions on this same graph.

4. Build an adjacency matrix

Choose and retain one vertex ordering for rows and columns. For an unweighted simple graph, entry ij is 1 if an edge leads from i to j and 0 otherwise in the row-origin convention used here. A simple undirected graph gives a symmetric matrix with zero diagonal. Multiple edges can be represented by counts. A weighted adjacency matrix storing costs is not the same object as a 0–1 adjacency matrix used to count walks.

5. Powers count walks

Row-column multiplication sums all possible intermediate vertices. Consequently \((A^n)_{ij}\) counts length-n walks from i to j when A stores edge counts. Such walks may revisit vertices and edges. Do not interpret a powered weighted-cost matrix as shortest-route distances under ordinary matrix multiplication. A zero-length walk stays at its starting vertex, which is encoded by the identity matrix.

Walk-counting powers

Why this formula works

A two-step walk selects a first edge from i to k and a second from k to j. For each intermediate k, multiplication counts the combinations, and addition combines the alternatives. Repeating this reasoning gives the general adjacency-power rule for walks of any fixed length.

The formula

\((A^2)_{ij}=\sum_k a_{ik}a_{kj}\).

Quick example

For a three-vertex chain A–B–C, there are two two-step walks from B back to B, through A or C.

Worked example: Count on a three-vertex chain

Use vertex order A,B,C with edges A–B and B–C. Find length-two walks from A.

  1. The adjacency matrix is \(\begin{pmatrix}0&1&0\\1&0&1\\0&1&0\end{pmatrix}\).
  2. Its square is \(\begin{pmatrix}1&0&1\\0&2&0\\1&0&1\end{pmatrix}\).
  3. The first row says one walk back to A, none to B, and one to C.
  4. A–B–A repeats the starting vertex, so it is a walk but not a simple path.
Worked example: Return walks in a triangle

A simple undirected triangle has vertices A,B,C. Count two-edge walks from A back to A.

  1. The first move can go to B or C.
  2. Each of those neighbours has an edge back to A.
  3. The two walks are A–B–A and A–C–A.
  4. The AA entry of the squared adjacency matrix is 2. The original diagonal entry is 0 because the graph has no loops.

6. Connect the graph to a real problem

An algorithm answers a particular objective: fewest steps, least total cost, coverage of edges or visiting selected locations. The same drawing may support all of these questions but requires different mathematics. Check whether weights are distances, times or capacities; their numerical operations differ. A graph simplification can omit road restrictions or transfer penalties. State what the chosen abstraction preserves and what it leaves out before interpreting a recommended route.

Quick formula reference

For revision once you understand the methods above. Check the conditions before using a formula.

Handshake relation

\(\sum_v\deg(v)=2|E|\) for an undirected graph.

Return to the explanation →

Walk-counting powers

\((A^2)_{ij}=\sum_k a_{ik}a_{kj}\).

Return to the explanation →

Learn to diagnose an error

Spot the mistake

The statement below is incorrect. Identify the missing condition or reasoning before opening the explanation.

Incorrect reasoning

An entry of A³ counts the number of simple paths with three edges.

Explain and repair the mistake

Ordinary adjacency powers count walks, which can repeat vertices and edges. On a single undirected edge A–B, the length-three walk A–B–A–B is counted even though it is not a simple path. A separate restriction is needed for path counting.

03

Connect and apply

Put the ideas together

A more demanding application of this guide’s methods. This is a learning stage; any additional HL content is labelled separately.

Worked application

A diagonal power entry is a return count

What does a positive diagonal entry of A⁴ tell you about a vertex?

  1. The row and column name the same starting and ending vertex.
  2. The exponent counts four edges, not four distinct vertices.
  3. A positive entry means at least one four-step return walk exists.
  4. It does not establish an Euler circuit or a Hamiltonian cycle, which impose additional global constraints.
Pause and explain

Can a four-step return walk consist of repeated use of one edge?

Check your reasoning

Yes on an undirected edge: A–B–A–B–A. This is one reason return-walk counts cannot be read as counts of simple cycles.

Common mistakes and how to avoid them

  • Ordinary adjacency powers count walks, which can repeat vertices and edges. On a single undirected edge A–B, the length-three walk A–B–A–B is counted even though it is not a simple path. A separate restriction is needed for path counting.
  • Do not interpret weighted costs under ordinary matrix powers as shortest-path distances.
  • A locally cheapest move may fail a global objective unless the algorithm has the appropriate guarantee.
04

Practise independently

Build confidence, then apply it

Try each question before opening its hint or solution. If a method is new, return to the walkthrough, then try again. These learning stages describe the practice sequence; additional HL content is labelled separately.

  1. 1

    Build confidence

    HL extension

    Add edge AD to a new vertex D. Find the new degrees.

    Need a starting point?

    Update both ends of the new edge.

    Show the worked solution
    1. The degrees become A:3, B:2, C:2, D:1.
    2. Their sum is 8, twice the four edges.
  2. 2

    Apply and explain

    HL extension

    Does the original triangle have an Euler circuit?

    Need a starting point?

    Check connectivity and vertex-degree parity.

    Show the worked solution
    1. It is connected and every degree is even.
    2. Yes: A-B-C-A uses each edge once and returns to its start.
  3. 3

    Check your understanding

    An undirected graph has total vertex degree 12. How many edges does it have?

    Show the worked solution

    It has 6, because each undirected edge contributes two to the degree total, with loops counted twice at their vertex. This count does not specify the graph’s connectivity.

  4. 4

    Use the method

    How many length-two walks go from the middle vertex back to itself in A–B–C?

    Show the worked solution

    Two: B–A–B and B–C–B. The diagonal entry in the squared adjacency matrix is therefore 2. Both routes repeat B and are valid walks.

Finished? Use the linked question bank below to practise selecting the method without a guide telling you which rule to use.

Using these methods in exam questions

AI Paper 1

GDC required

Short-response questions still need mathematical setup and interpretation. Choose the correct tool, enter the model or data carefully, and check units and rounding.

AI Paper 2

GDC required

Extended-response questions connect several steps. Keep intermediate values at full precision and explain how each result answers the context.

For this topic: Sketch and label the relevant triangle or curve. Show which angle and radius a formula uses, check degree or radian mode, and give length, area and volume in the correct units.

HL only · GDC required

Paper 3: build a connected argument

Both AA HL and AI HL Paper 3 contain two extended problem-solving questions. A question develops a theme, so keep useful earlier results, test small cases and explain any proposed general rule. A calculator pattern can suggest a result; your mathematical reasoning must support it.

  1. Identify what the first part establishes and record the conditions under which it holds.
  2. When a later part introduces a new definition or model, connect it to methods you already know rather than assuming a new formula must have been memorised.
  3. Check the conclusion against an earlier numerical case and explain its meaning or limitation.

For the first-assessment-2021 courses. IB assessment reference ↗

Find a specific method or formula

Now practise the method

If you opened this guide from a question, return to that tab and try the method without looking at the example. Your answer stays in the question tab.

Practise this subtopic →

Want a broader practice session? Explore IB Maths AI HL practice questions →Try free IB Maths exam-style questions and worked solutions →

Original Arc Practice teaching notes for Maths AI. Core and HL sections are distinguished above. These notes follow the first-assessment-2021 course and are not an official IB publication or a complete syllabus checklist. IB course reference. Report a correction.