Description

An Adjacency List, is a graph, in map form. Its accomplished by using a Map where each key points to the neighbors.
?

Reach for when

You need to store a graph and walk each node's neighbors given a changing entry point.

Runtime

O(n^2)

Visualization

Adjacency List-1784055752176.webp509x297

Pseudocode

key<nodeid>:neighbors<nodeid[]>

Code

graph = {
    'A': ['B', 'D', 'E'],
    'B': ['A', 'C', 'D'],
    'C': ['B', 'F'],
    'D': ['A', 'B', 'F'],
    'E': ['A', 'F'],
    'F': ['C', 'D', 'E'],
}