Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Which graph representation should I use?

Adjacency list, adjacency matrix, or incidence matrix -- the right choice is entirely about which operation you need to be cheap.

Need to list a vertex's neighbors, or store a huge sparse graph compactly? Adjacency list. Need a single-pair "are these two adjacent" lookup in constant time, or to use matrix powers to count walks? Adjacency matrix. Either way, weigh the choice against how many vertices and edges the graph actually has -- an adjacency list costs O(V+E) space; an adjacency matrix always costs O(V^2), cheap only when the graph is dense.

Adjacency list

Adjacency / incidence matrix

Three different ways to store the same graph in a computer: a list of each vertex's neighbors, a matrix of who's adjacent to whom, or a matrix of which vertex touches which edge.

Choosing by cost

Graph settings

Calculator