Menu
Sign in

Graph Theory & Algorithms HL

IB Mathematics: Applications & Interpretation · Topic 3: Geometry & Trigonometry
www.jmaths.xyz
1
Vertices, Edges & Degree
A graph consists of vertices (nodes) connected by edges. The degree of a vertex is the number of edges meeting it.
Handshaking lemma
\( \sum \deg(v) = 2E \)
The sum of all vertex degrees equals twice the number of edges \( E \)
A B C D E deg(A) = 3 deg(B) = 3 deg(C) = 2 deg(D) = 3 deg(E) = 3 ∑ = 14 = 2×7 7 edges
Key terms: Simple graph = no loops or multiple edges. Connected = path between every pair of vertices. \( K_n \) (complete graph) = every vertex connected to every other.
2
Directed Graphs (Digraphs)
In a directed graph the edges have a direction (arrows). For a vertex \( v \): the out-degree = number of edges leaving \( v \); the in-degree = number of edges entering \( v \).
Digraph adjacency matrix
Entry \( a_{ij} \) = number of edges from \( i \) to \( j \) (so the matrix need not be symmetric).
Row sums = out-degrees · Column sums = in-degrees
Mini-example
A digraph has edges \( A\!\to\!B \), \( B\!\to\!C \), \( A\!\to\!C \). Find the in/out-degree of \( A \).
Out of \( A \): edges to \( B \) and \( C \) → out-degree \( = 2 \)
Into \( A \): no edges arrive → in-degree \( = 0 \)
Answer: out-degree \( = 2 \), in-degree \( = 0 \)
3
Adjacency Matrices & Walks
The adjacency matrix A is an \( n \times n \) matrix where entry \( a_{ij} \) = number of edges between vertex \( i \) and vertex \( j \).
Number of walks
The entry \( (i, j) \) of \( A^k \) gives the number of walks of length \( k \) from vertex \( i \) to vertex \( j \).
For walks of length \( k \) or less, use entry \( (i,j) \) of \( A + A^2 + \cdots + A^k \).
Worked Example
For the triangle \( K_3 \), \( A = \begin{pmatrix}0&1&1\\1&0&1\\1&1&0\end{pmatrix} \). How many walks of length 3 go from vertex 1 to vertex 2?
Compute \( A^3 \) on the GDC: \( A^3 = \begin{pmatrix}2&3&3\\3&2&3\\3&3&2\end{pmatrix} \)
Read entry \( (1,2) \) of \( A^3 \)
Answer: entry \( (1,2) = 3 \), so there are 3 walks of length 3 from vertex 1 to vertex 2
GDC: Matrix Powers
TI-84 Plus CE
Enter adjacency matrix in [A]: [2ND][xโปยน] (MATRIX) → Edit
Calculate: [A]^3 [ENTER] → read entry (1,2)
TI-Nspire CX II
Define: a := [[0,1,1][1,0,1][1,1,0]]
Calculate: a^3 → read entry (1,2)
Casio fx-CG50
Enter matrix in Mat A: [MENU] → Run-Matrix
Calculate: Mat A ^ 3 [EXE] → read entry (1,2)
Weighted adjacency table
A square table where entry \( (i,j) \) = the weight (cost/distance) of edge \( i\!-\!j \), with “–” or \( \infty \) where there is no edge.
This is the usual input for Prim’s algorithm and TSP nearest-neighbour — Prim’s reads naturally off this table.

Graph Theory & Algorithms HL

IB Mathematics: Applications & Interpretation · Topic 3: Geometry & Trigonometry
www.jmaths.xyz
4
Euler Trails & Circuits
An Euler trail uses every edge exactly once. An Euler circuit is an Euler trail that starts and ends at the same vertex.
Euler circuit exists if:
Every vertex has even degree
(and graph is connected)
Euler trail exists if:
Exactly 2 vertices have odd degree
Trail starts/ends at the odd-degree vertices
Euler circuit: all vertices have even degree 2 2 2 2 all even circuit exists 3 2 3 2 2 odd trail only
Common error: Confusing Euler (every \( edge \) once) with Hamilton (every \( vertex \) once). Remember: Euler = Edges.
5
Hamiltonian Paths & Cycles
A Hamiltonian path visits every vertex exactly once. A Hamiltonian cycle visits every vertex exactly once and returns to the start.
No simple test: Unlike Euler, there is no quick rule to determine if a Hamiltonian path/cycle exists. You must search by trial. The IB only tests small graphs where this is feasible.

Graph Theory & Algorithms HL

IB Mathematics: Applications & Interpretation · Topic 3: Geometry & Trigonometry
www.jmaths.xyz
6
Minimum Spanning Trees (MST)
A spanning tree connects all vertices with no cycles, using \( n - 1 \) edges. The MST has the minimum total weight.
Kruskal’s algorithm
1. List all edges by weight (ascending)
2. Add the cheapest edge that does NOT form a cycle
3. Repeat until \( n - 1 \) edges added
Prim’s algorithm
1. Start at any vertex
2. Add the cheapest edge connecting a visited vertex to an unvisited one
3. Repeat until all vertices included
Worked Example — Kruskal’s
Edges: AB=3, BC=5, AC=7, BD=4, CD=6. Find the MST for vertices A, B, C, D.
Sort: AB=3, BD=4, BC=5, CD=6, AC=7
Add AB=3 (no cycle), BD=4 (no cycle), BC=5 (no cycle). Now 3 edges = \( n-1 = 3 \). Done.
Skip CD=6 (would form cycle B-C-D-B)
Answer: MST = {AB, BD, BC}, total weight = 3 + 4 + 5 = 12
Weighted graph 3 5 4 6 7 A B C D MST (total = 12) 7 6 3 4 5 A B C D
Kruskal vs Prim: Kruskal’s works well with edge lists. Prim’s works well with adjacency matrices (table form). The IB may specify which to use.
7
Travelling Salesman Problem (TSP)
Find the shortest Hamiltonian cycle (visit every vertex exactly once and return). This is NP-hard — we use heuristics for approximation.
Nearest neighbour algorithm (upper bound)
1. Start at a given vertex
2. Move to the nearest unvisited vertex
3. Repeat until all visited, then return to start
Gives an upper bound — a feasible route
Lower bound (deleted vertex)
1. Delete a vertex and all its edges
2. Find MST of remaining graph
3. Add back the two shortest edges to the deleted vertex
Gives a lower bound — optimal \( \geq \) this value
Optimal solution satisfies: lower bound \( \leq \) optimal \( \leq \) upper bound.
Common error: The nearest neighbour does NOT guarantee the optimal route. It is a greedy heuristic. Starting from different vertices may give different (better or worse) results.
8
Chinese Postman Problem
Find the shortest route that traverses every edge at least once and returns to the start. (Think: a postman delivering to every street.)
Algorithm
1. Identify all vertices with odd degree
2. Find the shortest pairings of odd vertices
3. Add these “extra” edges (repeat them) to make all degrees even
4. Total distance = sum of all edges + repeated edges
If all vertices have even degree: the graph already has an Euler circuit. No extra edges needed — total distance = sum of all edge weights.
Common error: With 4 odd vertices (A, B, C, D), there are 3 possible pairings: {AB+CD}, {AC+BD}, {AD+BC}. You must check all three and pick the minimum total. Do not just pick the first pairing.

Graph Theory & Algorithms HL

IB Mathematics: Applications & Interpretation · Topic 3: Geometry & Trigonometry
www.jmaths.xyz
9
Transition Matrix from a Graph
For a strongly-connected graph (every vertex reachable from every other), you can build a transition matrix \( T \) describing a random walk along the edges.
Constructing \( T \)
Divide each adjacency-matrix entry by the (out-)degree of its column vertex, so each column sums to 1.
Entry \( T_{ij} \) = probability of moving from \( j \) to \( i \) along a randomly chosen available edge. A vertex of out-degree 3 gives column entries of \( \tfrac{1}{3} \) to each neighbour.
Mini-example
From vertex \( A \) there are edges to \( B \), \( C \) and \( D \). Build column \( A \) of \( T \).
Out-degree of \( A = 3 \), so each available move has probability \( \tfrac{1}{3} \)
Answer: column \( A = \left(0, \tfrac{1}{3}, \tfrac{1}{3}, \tfrac{1}{3}\right)^{\mathsf T} \) (entries for \( A,B,C,D \))
Steady state lives elsewhere: long-term Markov-chain analysis (solving \( T\mathbf{s} = \mathbf{s} \), powers \( T^n \), eigenvector with eigenvalue 1) is Statistics topic 4.19 — see the Vectors & Matrices sheet.
Common error: Columns (not rows) of a transition matrix must sum to 1 — divide by the column vertex’s out-degree, not the row vertex’s.
10
Exam Traps & Key Reminders
Show your working. For algorithms (Kruskal, Prim, nearest neighbour), list each step clearly. The IB awards marks for the process, not just the answer.
TSP bounds: Always state both upper and lower bounds. The optimal solution lies between them. If they are equal, you have found the optimal route.
Quick checks: A tree with \( n \) vertices has exactly \( n - 1 \) edges. A complete graph K\( n \) has \( n(n-1)/2 \) edges. There is always an even number of odd-degree vertices.
Formula booklet: The adjacency-matrix walk result is given. The algorithms (Kruskal, Prim, nearest neighbour, Chinese postman) are NOT in the booklet — learn the steps.