Structure of an adjacency matrix


Now that we know the logical representation of a graph and how it stores many relationships between data, we can look at how it can be implemented in computer memory as a data structure. An adjacency matrix is the simplest way to implement a graph in any language. Consider the following graph as an example.

Loading Image

An example graph

If we look at the graph as a set of edges connecting different nodes, the easiest way to implement it in memory is to store all its edges. If we map the relationship of one node with all other nodes in a matrix, we can store the graph as a matrix.

Liking the course? Check our discounted plans to continue learning.