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 vertices, an adjacency matrix is an square matrix where each entry represents the connection between vertex and vertex :
- if there is an edge from vertex to vertex
- if there is no direct edge from vertex to vertex
The power of this representation is that it transforms graph problems into matrix problems , and matrices are something we can compute with directly.
For a simple graph (one with no self-loops and no multiple edges), the diagonal entries 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 can be any non-negative integer , it records the number of edges between vertex and vertex . For example, means there are three distinct edges between those two vertices.
For undirected graphs, the adjacency matrix is always symmetric: for all and . This is because an edge between vertices and 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 and then systematically fill in the grid.
Step-by-step process:
- List all vertices and assign each a row and a corresponding column.
- For each pair of vertices , determine whether an edge exists.
- Enter if an edge exists, if not (for a simple graph).
- The diagonal is always for simple graphs (no self-loops).
Consider an undirected simple graph with 5 vertices and the following edges:
To construct the adjacency matrix, place a in position and position for each edge (since the graph is undirected), and everywhere else. The diagonal entries are all .
Reading the matrix:
- Row , Column has entry → there is an edge between vertex and vertex . ✓
- Row , Column has entry → there is no direct edge between vertex and vertex . ✓
- The matrix is symmetric about the main diagonal, confirming this is an undirected graph. ✓
Degree check: The sum of row equals the degree of vertex .
- Vertex 1: → degree 3
- Vertex 4: → degree 4
A quick check: in an undirected graph, the sum of row (or column ) equals the degree of vertex , the number of edges connected to it.
Multigraph example: Suppose vertices and are connected by 2 edges, and and are connected by 1 edge, with no other connections. The adjacency matrix is:
Note that entries can be greater than for multigraphs. The matrix remains symmetric for an undirected multigraph.