An adjacency matrix is a two-dimensional matrix used to map the association between the nodes of a graph. A graph is a set of vertices (nodes) connected by edges.
In an adjacency matrix,
0
means that no association between nodes exists and1
means that an association between nodes does exist.
In the example below, we have implemented the adjacency matrix for the above illustration.
In a two-dimensional matrix, rows and columns are initialized with index
0
and so on. That’s why we have subtracted1
from each index below.