An adjacency matrix is a way to represent a graph using a square table (matrix). If a graph has n vertices, then its adjacency matrix is an n × n matrix where:
- Entry 1 means there is an edge between the two vertices.
- Entry 0 means there is no edge.
- The diagonal entries are usually 0 because a vertex is not connected to itself.
Example: Consider these graphs and their adjacency matrices.

How to read it:
For 1st graph
- Row 1 =
[0 0 0 1],Vertex 1 is connected to 4. - Row 2 =
[0 0 0 1],Vertex 2 is connected to 4. - Row 3 =
[0 0 0 1],Vertex 3 is connected to 4. - Row 4 =
[1 1 1 0],Vertex 4 is connected to 1, 2 and 3.
The second and third graphs can be read similarly using the same row-wise interpretation of the adjacency matrix.
Note: An adjacency matrix is always read row-wise. In row i, a 1 in column j indicates that Vertex i is connected to Vertex j, while a 0 indicates no connection..
Multiple Adjacency Matrix Representations
A graph can have multiple adjacency matrix representations because its vertices can be labelled in different ways. Although changing the vertex labels alters the arrangement of rows and columns in the matrix, the underlying graph structure and connections remain unchanged.

The image above shows different adjacency matrix representations of the same graph obtained by changing the vertex labels.
Creating an Adjacency Matrix
An adjacency matrix is formed by listing all the vertices of a graph as both the rows and columns of a square matrix. If an edge exists between two vertices, the corresponding entry is 1; otherwise, it is 0. For a graph without self-loops, all diagonal entries are 0.
For a graph containing vertices V₁, V₂, ..., Vₙ, the adjacency matrix is a square matrix used to represent the connections between the vertices. It is written as:
Where,
Example: Consider the directed graph shown below with five vertices P1, P2, P3, P4, P5. By examining the connections between the vertices, we can construct its adjacency matrix.

The adjacency matrix of the given graph is:
A=\begin{bmatrix}0 & 1 & 0 & 1 & 1\\1 & 0 & 1 & 1 & 0\\0 & 0 & 0 & 1 & 1\\1 & 0 & 1 & 0 & 1\\0 & 0 & 0 & 0 & 0\end{bmatrix}
Steps to Construct an Adjacency Matrix
The following steps explain how an adjacency matrix is created from a graph by recording the connections between its vertices.
Step 1: List all vertices of the graph as both the row and column headings of a square matrix.
Step 2: Examine the graph and identify the connections between the vertices.
Step 3: Examine each pair of vertices and record their connection in the matrix by writing 1 for an edge and 0 for no edge
Step 4: Continue this process for all vertex pairs until the entire matrix is filled.
Adjacency Matrix of an Undirected Graph
In an undirected graph, an edge between two vertices indicates a connection in both directions. Therefore, the adjacency matrix is symmetric, meaning the value at position (i,j) is the same as the value at position (j,i).
The graph shown below illustrates the connections between six vertices.

The adjacency matrix corresponding to the given graph is:
- The matrix is symmetric because the graph is undirected.
- A value of 1 indicates that two vertices are connected by an edge.
- A value of 0 indicates that no direct connection exists between the vertices.
- The connections of any vertex can be identified by examining its corresponding row or column in the matrix.
Adjacency Matrix of a Directed Graph
In a directed graph, each edge has a specific direction from one vertex to another. While constructing the adjacency matrix, a value of 1 is entered if there is a directed edge from vertex Vi to vertex Vj ; otherwise, 0 is entered.
The directed graph shown below illustrates the connections between the vertices.

The adjacency matrix of the graph can then be constructed by recording the directed connections between all pairs of vertices.
- The direction of each edge is important when filling the matrix.
- A value of 1 indicates the presence of a directed edge.
- A value of 0 indicates that no directed edge exists.
- Unlike an undirected graph, the adjacency matrix of a directed graph is not necessarily symmetric.
Properties of an Adjacency Matrix
The adjacency matrix not only represents the connections in a graph but also helps in analyzing various graph properties. Some important properties are described below.
Matrix Powers
The powers of an adjacency matrix provide information about the paths between vertices in a graph. By multiplying the adjacency matrix by itself, we can determine the number of walks of a certain length between two vertices.
Theorem: If A is the adjacency matrix of a graph, then the entry (i,j) of An gives the number of walks of length nnn from vertex iii to vertex j.
Spectrum
The eigenvalues and eigenvectors of an adjacency matrix are studied in spectral graph theory. They help analyze the structural properties of a graph, such as connectivity and regularity.
For a k-regular graph, every vertex has exactly k edges. In this case, the all-ones vector is an eigenvector of the adjacency matrix with eigenvalue k.
Isomorphisms
Two graphs are said to be isomorphic if one graph can be obtained from the other by simply relabeling its vertices. Although isomorphic graphs may have different adjacency matrices, they represent the same graph structure.

Theorem: Let G and H be two graphs with adjacency matrices A and B, respectively. The graphs are isomorphic if there exists a permutation matrix P such that:
This relationship shows that the adjacency matrices of isomorphic graphs are closely related even when the vertex labels are different.
Example: Write the adjacency matrix for the given weighted undirected graph.

Solution:
In a weighted graph, the entries of the adjacency matrix represent the weights of the edges between vertices. If two vertices are not directly connected, the corresponding entry is 0.
The adjacency matrix of the given graph is:
A=\begin{bmatrix}0 & 3 & 0 & 0 & 0 & 12 & 0\\3 & 0 & 5 & 0 & 0 & 0 & 4\\0 & 5 & 0 & 6 & 0 & 0 & 3\\0 & 0 & 6 & 0 & 1 & 0 & 0\\0 & 0 & 0 & 1 & 0 & 10 & 7\\12 & 0 & 0 & 0 & 10 & 0 & 2\\0 & 4 & 3 & 0 & 7 & 2 & 0\end{bmatrix}
- Each non-zero entry indicates the weight of the edge between two vertices.
- A value of 0 indicates that no direct edge exists between the corresponding vertices.
- Since the graph is undirected, the adjacency matrix is symmetric. For example, the weight between vertices 1 and 2 is 3, so both entries (1,2) and (2,1) are 3.