Quiz Entry - updated: 2026.11.27
Adjacency list or adjacency matrix? (a) 10 000 vertices, 20 000 edges, using as little space as possible; (b) 10 000 vertices, 20 000 000 edges, removing vertices as fast as possible; (c) answering "are v and w adjacent?" as fast as possible, space no object.
- (a) Adjacency list: $n + m = 30\,000$ against $n^2 = 100\,000\,000$ cells.
- (b) Adjacency list:
removeVertexcosts $O(\deg(v))$, about 4 000 edges on average here, against $O(n^2) = 100\,000\,000$ for the matrix. - (c) Adjacency matrix: one cell lookup, $O(1)$, against $O(\min(\deg(v), \deg(w)))$.
Each answer comes from one row of the cost table, with the numbers filled in:
- Space. 20 000 edges among 10 000 vertices is very sparse, two edges per vertex on average. The list stores what exists, the matrix all 100 million possible pairs.
- Removing a vertex. With 20 million edges the average degree is $2m/n = 4\,000$, so the list unlinks about 4 000 edges. The matrix has to be rebuilt without one row and one column, copying all $10^8$ cells. Even with this many edges the list is still smaller: about 20 million edges against 100 million cells.
- Adjacency. Only the matrix answers in constant time, whatever the degrees; when space does not matter, that is the deciding row.