Adjacency list vs matrix

easy

A matrix costs V² whatever the edge count. For a social graph with a million users and fifty friends each, lists win by four orders of magnitude - and nearly every algorithm here wants a list.

Best O(1) matrix edge testWorst O(V) matrix neighboursSpace O(V²) matrix, O(V + E) list
Loading the adjacency list vs matrix engine…

Where to go next