Adjacency List
For this implementation
- We use a vector
, of length . - Each cell
, . - Is labeled in a way that reflects the given graph
- Contains a pointer to a linked list, where each element of the list represents a vertex
adjacent to , such that - Those elements are labeled too.
Furthermore
- For vertex-weighted graphs,
also contains the weight - For edge-weighted graphs, each element of the linked list has additional information for the weight
Example: this graph right here, would be implemented like this

Space
| Case | Space |
|---|---|
| Sparse Graph | |
| Dense Graph |
Time
Verifying adjacency in the case of a long linked-list, takes more time.
Conclusions
Because the adjacency-list representation provides a compact way to represent sparse graphs, it is usually the method of choice.
| Pros | Cons |
|---|---|
| Best for sparse graphs | Worst for dense graphs |
| Space complexity is not fixed to | Can worsen with dense graphs and large |
| Flexible structure for both undirected and directed graphs | Verifying adjacency when the lists are long, takes more time |