DP Math AI · HL · Geometry and Trigonometry

AHL 3.15—Adjacency matrices and tables

Get started
Notes

Introduction to Adjacency Matrices

Graph theory gives us powerful tools for modelling networks , social connections, transport systems, the internet, and more. One of the most useful representations of a graph is the adjacency matrix, which encodes the entire structure of a graph in a compact, mathematical format that we can manipulate algebraically.

Before defining the matrix, recall the key vocabulary:

  • A graph consists of vertices (nodes) connected by edges (links).
  • In an undirected graph, edges have no direction; in a directed graph (digraph), each edge has a specific direction from one vertex to another.
  • The degree of a vertex is the number of edges incident to it (for directed graphs, we distinguish in-degree and out-degree).

Adjacency Matrix: For a graph with n vertices, an adjacency matrix A is an n×n square matrix where each entry aij​ represents the connection between vertex i and vertex j:

  • aij​=1 if there is an edge from vertex i to vertex j
  • aij​=0 if there is no direct edge from vertex i to vertex j

The power of this representation is that it transforms graph problems into matrix problems , and matrices are something we can compute with directly.

Note

For a simple graph (one with no self-loops and no multiple edges), the diagonal entries aii​ are always 0, since no vertex is connected to itself.

For a multigraph (where two vertices may be connected by more than one edge), the entry aij​ can be any non-negative integer , it records the number of edges between vertex i and vertex j. For example, aij​=3 means there are three distinct edges between those two vertices.

Note

For undirected graphs, the adjacency matrix is always symmetric: aij​=aji​ for all i and j. This is because an edge between vertices i and j goes both ways. For directed graphs (digraphs), the matrix is generally not symmetric.

Constructing an Adjacency Matrix

To build an adjacency matrix, label the vertices 1,2,3,…,n and then systematically fill in the n×n grid.

Step-by-step process:

  1. List all vertices and assign each a row and a corresponding column.
  2. For each pair of vertices (i,j), determine whether an edge exists.
  3. Enter 1 if an edge exists, 0 if not (for a simple graph).
  4. The diagonal is always 0 for simple graphs (no self-loops).
Example

Consider an undirected simple graph with 5 vertices and the following edges:
1–2,1–4,1–5,2–3,2–4,3–4,3–5,4–5

To construct the adjacency matrix, place a 1 in position (i,j) and position (j,i) for each edge (since the graph is undirected), and 0 everywhere else. The diagonal entries are all 0.

A=​01011​10110​01011​11101​10110​​

Reading the matrix:

  • Row 1, Column 2 has entry 1 → there is an edge between vertex 1 and vertex 2. ✓
  • Row 1, Column 3 has entry 0 → there is no direct edge between vertex 1 and vertex 3. ✓
  • The matrix is symmetric about the main diagonal, confirming this is an undirected graph. ✓

Degree check: The sum of row i equals the degree of vertex i.

  • Vertex 1: 0+1+0+1+1=3 → degree 3
  • Vertex 4: 1+1+1+0+1=4 → degree 4
Exam Tip

A quick check: in an undirected graph, the sum of row i (or column i) equals the degree of vertex i , the number of edges connected to it.

Example

Multigraph example: Suppose vertices A and B are connected by 2 edges, and B and C are connected by 1 edge, with no other connections. The adjacency matrix is:

A=​020​201​010​​

Note that entries can be greater than 1 for multigraphs. The matrix remains symmetric for an undirected multigraph.

Free preview

9 more sections in this topic

← Previous topicAHL 3.14—Graph theoryNext topic →AHL 3.16—Tree and cycle algorithms, Chinese postman, travelling salesman
Koncepts

Learn it properly. Then practise like it's the real paper.

Start free

Features

  • Lessons
  • Past papers
  • Library
  • Homework Help
  • Duels

More

  • For parents
  • Compare
  • Plans & pricing
  • DP for students

Legal

  • Privacy
  • Terms
  • Account deletion

© 2026 Koncepts (product of PrepAiro, Inc). All rights reserved.
DP, IB, EE and TOK are terms of the International Baccalaureate Organization.

Made for IB DP students.