An adjacency list keeps, for each vertex, a list of its neighbors. An adjacency matrix keeps a grid with one row and one column per vertex. The cell at row i, column j marks whether an edge joins those two vertices.
list: A -> [B, C]
matrix: A row = [0, 1, 1, 0]
These two layouts dominate, and they trade memory for lookup speed. 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.
Lookup speed favors the matrix. Checking whether a specific edge exists is O(1) in a matrix but needs a scan of the list.
Most real graphs are sparse, so adjacency lists are the default choice. Use the matrix only when the graph is small or dense, or when you test single edges constantly.
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 ↓