Sparse and Dense Graph Representations

The number of actual edges guides how much work and storage different graph representations need.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Compare two four-vertex graphs
  2. Choose the operations to favor
  3. Compare storage counts on a fixed-size vertex set
  4. Choose the representation from access patterns as well as size

Compare two four-vertex graphs

A path on four vertices has three edges. A complete graph has six. For large \(n\), a single long path has a linear edge count while a complete simple graph has quadratic edge count. See complete graph counting.

Choose the operations to favor

An adjacency matrix reserves a position for every possible pair. A list representation stores observed neighbors, which can be much smaller for sparse graphs. Edge lists and matrices distinguish lookup and iteration costs.[1]

Compare storage counts on a fixed-size vertex set

For one thousand vertices, a chain has nine hundred ninety-nine undirected edges, while a complete graph has four hundred ninety-nine thousand five hundred. A dense adjacency matrix allocates space for one million entries in both cases before exploiting symmetry or bit packing. See edge lists versus matrices.

Chain: m=999, average degree about 2
Complete simple graph: m=499500, degree 999
Adjacency lists store 2m incidences for undirected edges

Choose the representation from access patterns as well as size

Enumerating neighbors of a low-degree vertex is cheap in an adjacency list. Checking one arbitrary pair is natural in a matrix. Memory budgets depend on actual bytes per cell and edge. Compare the chosen operations on graphs at both densities.

References

  1. Eric Lehman, F. Thomson Leighton and Albert R. Meyer, Mathematics for Computer Science ↩