Structure of adjacency list
Now that we know the limitations of the adjacency matrix implementation, let's look at another way of implementing graphs that overcome those limitations. Consider the following graph as an example.
Loading Image
An example graph
Instead of looking at the graph as a set of edges connecting the nodes, if we look at the graph as a set of nodes connected, we can implement the graph from the point of view of nodes. For every node, we can store all the nodes directly connected to it by an edge in a list, also called the adjacency list. This way, the entire graph can be implemented as a list of adjacency lists.
Liking the course? Check our discounted plans to continue learning.