LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

How do the edge list, the adjacency list and the adjacency matrix compare in space and running time?

The adjacency list needs $O(n + m)$ space and answers everything about one vertex in $O(\deg(v))$. The matrix spends $n^2$ space and $O(n^2)$ vertex updates to get $O(1)$ adjacency tests. The edge list is the simplest but needs $O(m)$ for every question about a vertex.

For $n$ vertices and $m$ edges, without parallel edges and self-loops:

Edge list Adjacency list Adjacency matrix
Space $n + m$ $n + m$ $n^2$
incidentEdges(v) $m$ $\deg(v)$ $n$
areAdjacent(v, w) $m$ $\min(\deg(v), \deg(w))$ $1$
insertVertex(o) $1$ $1$ $n^2$
insertEdge(v, w, o) $1$ $1$ $1$
removeVertex(v) $m$ $\deg(v)$ $n^2$
removeEdge(e) $1$ $1$ $1$

The pattern behind the table: each structure answers fastest what it stores directly. The edge list stores edges, so edge updates are cheap. The adjacency list stores each vertex's edges, so vertex-centred questions are cheap. The matrix stores every pair of vertices, so the pair question is cheap, and anything that changes the set of vertices is expensive. So the choice follows the algorithm: if its main operation is testing whether two vertices are adjacent, the matrix; if it mostly walks the edges at a vertex, the adjacency list.

Go deeper:

From Quiz: ADS / Graphs: Basics, Representations and Spanning Trees | Updated: Dec 01, 2026