HL AI · Geometry and Trigonometry

Graph theory — adjacency matrices, spanning trees and route problems (IB Math AI HL)

Updated October 2026

Quick answer: Graph theory in HL AI is about graphs drawn as vertices and edges: the adjacency matrix (the (i, j) entry of Aⁿ counts walks of length n), minimum spanning trees (Kruskal and Prim), Eulerian and Hamiltonian circuits, and route problems such as the Chinese postman problem.

Vertices, edges and the adjacency matrix, where the (i, j) entry of An counts the walks of length n. Then minimum spanning trees with Kruskal and Prim, Eulerian and Hamiltonian circuits, and the Chinese postman problem, each with a worked example.

Practise Graph theory — adjacency matrices, spanning trees and route problems with AI marking

Open the full HL AI engine — every question in this unit is worked through with instant AI-graded feedback on your handwritten workings.

Practise HL AI Geometry and Trigonometry →

Key ideas

Worked example

A graph has vertices A, B, C and D and edges AB, AC, BC and CD. Write down its adjacency matrix and find the number of walks of length 3 from A to C.

  1. In the order A, B, C, D, the rows of the adjacency matrix are (0 1 1 0), (1 0 1 0), (1 1 0 1), (0 0 1 0).
  2. On the GDC, the (A, C) entry of A³ is 4.
  3. Check by listing: A–B–A–C, A–C–A–C, A–C–B–C and A–C–D–C.

Answer: 4 walks of length 3.

Minimum spanning trees: Kruskal and Prim

Kruskal's algorithm: add edges in order of increasing weight, skipping any that would make a cycle, until you have n − 1 edges. Prim's algorithm: start at one vertex and keep adding the cheapest edge that joins a new vertex to the tree.

Worked example

A weighted graph has vertices A, B, C, D and E and edges AB = 4, AC = 3, AD = 7, BC = 2, BE = 6, CD = 5, CE = 8 and DE = 4. Use Kruskal's algorithm to find a minimum spanning tree and its weight.

  1. In order of weight: BC 2, AC 3, AB 4, DE 4, CD 5, BE 6, AD 7, CE 8.
  2. Add BC (2), then AC (3).
  3. AB (4) would make the cycle A–B–C, so reject it. Add DE (4).
  4. Add CD (5). That is 4 edges for 5 vertices, so stop.
  5. Weight = 2 + 3 + 4 + 5 = 14. (Prim from A adds AC, CB, CD, DE: the same total.)

Answer: Edges BC, AC, DE and CD, total weight 14.

Eulerian and Hamiltonian circuits

An Eulerian circuit uses every edge exactly once and exists in a connected graph when every vertex has even degree; with exactly two odd vertices there is an Eulerian trail instead. A Hamiltonian cycle visits every vertex exactly once, and there is no simple degree test for it.

Worked example

A connected graph has five vertices with degrees 2, 4, 3, 3 and 2. How many edges does it have? Does it have an Eulerian circuit or an Eulerian trail? How many Hamiltonian cycles does K₅ have?

  1. Sum of degrees = 2 + 4 + 3 + 3 + 2 = 14, so there are 14 ÷ 2 = 7 edges.
  2. Two vertices have odd degree, so there is no Eulerian circuit.
  3. There is an Eulerian trail, starting at one vertex of degree 3 and ending at the other.
  4. K₅ has (5 − 1)!/2 = 12 Hamiltonian cycles.

Answer: 7 edges; an Eulerian trail but no circuit; 12 Hamiltonian cycles in K₅.

The Chinese postman problem

Find the vertices of odd degree. If there are none, the shortest route is the total weight of all the edges. If there are two, add the shortest path between them. If there are four, try all three pairings and add the cheapest.

Worked example

A graph has edges AB = 5, BC = 7, CD = 6, DA = 8 and AC = 13. Find the length of the shortest route that travels along every edge and returns to the start.

  1. Degrees: A = 3, B = 2, C = 3, D = 2. The odd vertices are A and C.
  2. Total weight = 5 + 7 + 6 + 8 + 13 = 39.
  3. Shortest path from A to C: direct 13, A–B–C = 12, A–D–C = 14. So the shortest is A–B–C = 12.
  4. Route length = 39 + 12 = 51, with AB and BC travelled twice.

Answer: 51

Exam-style HL AI questions on this topic

Try it now

1 of 5

  1. Question 1 of 5
  2. Question 2 of 5
  3. Question 3 of 5
  4. Question 4 of 5
  5. Question 5 of 5

5 quick questions on graph theory. No sign-in needed.

A graph has vertices A–E and edges AB = 2, BC = 3, AC = 4, BD = 5, BE = 6, CD = 8, DE = 7 (weights). Find the total weight of a minimum spanning tree.
Choose your answer · keys 1–4

Maths IA ideas that use graph theory

Related in Geometry and Trigonometry

Revise Graph theory for the exam

Stretch yourself: original combinatorics problems at Senior level (ages 16 to 18), with hints and full solutions: Problem S57 · Problem S08 · Problem S56 · Problem S63. All 22 →

More on this topic

FAQ

How do you solve the Chinese postman problem?

Add up all the edge weights. Then find the odd-degree vertices, pair them so the total of the shortest paths between the pairs is as small as possible, and add that total.

What is the difference between Eulerian and Hamiltonian?

An Eulerian circuit uses every edge exactly once. A Hamiltonian cycle visits every vertex exactly once. A graph can have one, both or neither.

What is the difference between Kruskal's and Prim's algorithm?

Kruskal's picks the cheapest edges anywhere in the graph, skipping any that make a cycle. Prim's grows one tree from a starting vertex, always adding the cheapest edge to a new vertex. Both give a minimum spanning tree of the same weight.

How do you count walks using an adjacency matrix?

Raise the adjacency matrix to the power n on your GDC. The entry in row i, column j is the number of walks of length n from vertex i to vertex j.

Where can I practise graph theory questions?

On the Graph Theory questions page: 86 exam-style HL AI questions with full mark schemes, plus free step-by-step worked examples.

Can I use my calculator for graph theory?

Yes: a GDC is allowed on every HL AI paper, so practise the calculator method as well as the working.

What else is free here

Save your progress as you reviseA free account remembers the questions you have done on every topic and brings you back to this page.

Join free

Already have an account? Sign in