Adjacency List

Discover how graphs can be represented in code using adjacency lists.

The second option to represent graph edges in code is the adjacency list.

Adjacency list

In this data structure, we store a list of each node’s neighbors.

Let’s look at our example graph again. We use the same integer encoding of nodes that we did for the adjacency matrix.

g 2 2 0 0 2->0 3 3 2->3 1 1 0->1 1->2 1->0 1->3
The example graph with integer node names

The node with index 11 has three neighbors: 00 ...