Two layouts dominate, and they trade memory for lookup speed. An adjacency list keeps, for each vertex, a list of its neighbors. An adjacency matrix keeps a grid of size vertices-by-vertices, where cell (i, j) marks whether an edge exists.
The cost difference is the point. A list uses space proportional to O(V + E), which is tiny when edges are few. A matrix always uses O(V^2), even for a nearly empty graph.
list: A -> [B, C]
matrix: A row = [0, 1, 1, 0]
Speed flips the other way. Checking whether a specific edge exists is O(1) in a matrix but needs scanning a list. Most real graphs are sparse, so adjacency lists are the default choice. You reach for the matrix only when the graph is small or dense, or when you constantly test single edges.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓