Adjacency List
Explore how to represent graphs using adjacency lists in C++. This lesson helps you understand storing neighbors for each node with vectors, improving efficiency for graph algorithms compared to adjacency matrices. You will learn the structure and implementation details behind adjacency lists to apply in various graph problems.
We'll cover the following...
We'll cover the following...
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.
The example graph with integer node names
The node with index has three neighbors: ...