LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

What makes a graph sparse or dense, and how does that decide between adjacency list and matrix?

A graph is sparse when its number of edges is far below the maximum $n(n-1)/2$, typically proportional to $n$, and dense when it comes close to that maximum. Sparse graphs, which most real networks are, belong in adjacency lists with $O(n + m)$ space; the matrix's $n^2$ cells only pay off for dense graphs, or small ones where constant-time adjacency tests matter.

The average degree $2m/n$ shows which case you have. In a road network every junction has a handful of roads, whether the country has a thousand junctions or a million: the average degree stays a small constant and $m$ grows like $n$. A social network is sparse too: a person may have hundreds of contacts, but that is a tiny fraction of the millions of other people.

The matrix ignores that: for a million vertices it has $10^{12}$ cells, a terabyte even at one byte per cell, almost all of them empty. Dense graphs do exist, for example a table of the distances between every pair of cities, where every pair is joined; then the matrix wastes nothing and its $O(1)$ lookups are the better deal.

Go deeper:

  • doc Dense graph โ€” density as a number, and what sparse and dense mean precisely.

From Quiz: ADS / Graphs: Basics, Representations and Spanning Trees | Updated: Nov 27, 2026