Skip to content
DSA Visualizerpreview

Adjacency list vs matrix

The same graph as lists of neighbours and as a grid of 0s and 1s, built edge by edge.

list: O(degree) edge check; matrix: O(1) time · list: O(V + E); matrix: O(V²) space

EdgesA-B, A-C, B-D, C-D, D-E

5 nodes. The lists start empty; the matrix already has 5 × 5 = 25 cells, all 0.

5 nodes, 0 edges so far. List: A: none; B: none; C: none; D: none; E: none.
  • compare
  • swap or write
  • settled

1 / 7

Speed

Space play · ← → step · Home End jump · drag the strip to scrub