Study Guide

Graph theory: adjacency matrices, paths and cycles

IB Mathematics Applications and Interpretation HLΒ· Unit 5: Statistics and probability, Topic 12: Graph theoryΒ· 15 min read

1. Constructing Adjacency Matricesβ˜…β˜†β˜†β˜†β˜†β± 5 min

πŸ“˜ Definition

Adjacency Matrix

, for vertices

Entry counts the number of edges from vertex to vertex . Undirected graphs produce symmetric matrices, directed graphs are often asymmetric.

Example:

A 3-vertex undirected triangle has all off-diagonal entries equal to 1.

Loops (edges that start and end at the same vertex) are recorded on the main diagonal of the matrix. Adjacency matrices are a compact, computer-friendly way to store graph information for further calculations.

πŸ“ Worked Example

Construct the adjacency matrix for the directed graph with vertices , with edges: , , , .

  1. 1

    Confirm the matrix will be , with rows for starting vertices and columns for ending vertices.

  2. 2

    Fill row 1 (from ): , ,

  3. 3

    Fill row 2 (from ): , ,

  4. 4

    Fill row 3 (from ): , ,

  5. 5

    Final adjacency matrix:

  6. 6
    (011001100)\begin{pmatrix} 0 & 1 & 1 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{pmatrix}

2. Counting Paths with Matrix Powersβ˜…β˜…β˜…β˜†β˜†β± 8 min

The core property of adjacency matrices is: the entry of (the -th power of ) equals the number of distinct paths of exactly edges between vertex and vertex . This holds for both directed and undirected graphs.

πŸ“ Worked Example

For the adjacency matrix from the previous example, how many paths of length 2 are there from to ?

  1. 1

    Calculate :

  2. 2
    (011001100)(011001100)=(101100011)\begin{pmatrix} 0 & 1 & 1 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{pmatrix} \begin{pmatrix} 0 & 1 & 1 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 1 \end{pmatrix}
  3. 3

    The entry for start at (row 1) and end at (column 3) is 1.

  4. 4

    There is exactly 1 path of length 2 from to : .

βœ“ Quick check

Test your understanding of convention:

  1. What does the entry in represent?

    • Number of paths of length 2 from to

    • Number of paths of length 2 from to

    • Number of cycles of length 2 starting at

    Reveal answer
    Number of paths of length 2 from $V_2$ to $V_1$ β€”

    Rows always correspond to starting vertices, columns to ending vertices, so entry counts paths from to .

3. Identifying Cycles with Adjacency Matricesβ˜…β˜…β˜…β˜†β˜†β± 6 min

A cycle is a path that starts and ends at the same vertex, so all cycles of length are counted on the main diagonal of . The sum of the main diagonal entries is called the trace of , and gives the total number of cycles of length in the entire graph.

πŸ“˜ Definition

Trace of a Matrix

The sum of all entries on the main diagonal of a square matrix. For , equals the total number of cycles of length in the graph.

πŸ“ Worked Example

Find the total number of cycles of length 2 in the 3-vertex directed graph from earlier.

  1. 1

    We already have with diagonal entries .

  2. 2

    Calculate the trace:

  3. 3
    tr(A2)=1+0+0=1\text{tr}(A^2) = 1 + 0 + 0 = 1
  4. 4

    There is exactly 1 cycle of length 2: .

4. Real-World Applicationsβ˜…β˜…β˜†β˜†β˜†β± 4 min

Adjacency matrices are used to model networks of all kinds: social connections, transport routes, website links, and supply chains. Counting paths helps answer questions about how information or goods flow through a network.

πŸ“ Worked Example

A social network has 3 users: A, B, C. A follows B and C, B follows C, C follows A. How many ways can a message starting at A reach C after exactly 2 followers?

  1. 1

    This network matches our example graph: A = , B = , C = .

  2. 2

    We already know the entry of is 1.

  3. 3

    There is exactly 1 path: A β†’ B β†’ C.

5. Common Pitfalls

Wrong move:

Swapping rows and columns for directed graphs, counting edges from to instead of to .

Why:

IB uses the convention rows = start, columns = end, reversing this gives all counts wrong.

Correct move:

Always label rows as the starting vertex and columns as the ending vertex when building the matrix.

Wrong move:

Interpreting as the number of paths of up to edges, not exactly edges.

Why:

Exam questions regularly ask for both specific lengths and cumulative lengths, mixing these up leads to wrong answers.

Correct move:

Use for exactly edges, sum to for up to edges.

Wrong move:

Counting loops as zero-length cycles, ignoring them when calculating trace.

Why:

A cycle requires at least one edge, so a loop is a valid cycle of length 1.

Correct move:

Include diagonal entries for loops when counting total cycles of any length.

Wrong move:

Setting for multigraphs, even when there are multiple edges between two vertices.

Why:

Multiple edges create multiple distinct paths, so they must be counted explicitly.

Correct move:

Set equal to the actual number of edges between and , not just 0 or 1.

6. Quick Reference Cheatsheet

Concept

Interpretation for Adjacency Matrices

Entry

Number of edges / length 1 paths from to

Entry

Number of paths of exactly edges from to

Entry in

Number of paths of up to edges from to

Diagonal entry

Number of cycles of length starting/ending at

Trace of

Total number of cycles of length in the graph

Undirected graph property

(adjacency matrix is symmetric)

When this came up on past exams

AI-estimated based on syllabus patterns β€” cross-check with official past papers for accuracy. Use only as revision-focus signals.

  • 2021 Β· 2

    Count paths between towns

  • 2022 Β· 1

    Count cycles in directed graph

  • 2023 Β· 2

    Social network path counting

Going deeper

What's Next

Adjacency matrices are the foundation for all advanced graph theory problems you will encounter in IB AI HL, including shortest path algorithms, connected component analysis, and network optimization. Counting paths and cycles is regularly tested in both Paper 1 (small non-calculator matrices) and Paper 2 (larger calculator-assisted problems), so mastering this convention and matrix multiplication is key to scoring full marks. Beyond the exam, adjacency matrices are core tools in computer science, network analysis, operations research, and data science for modeling all kinds of connected systems.