StudyG Logo
Study G
Concept Breakdowns

Graph Adjacency List vs Adjacency Matrix

Choosing the right graph representation — adjacency list or adjacency matrix — directly impacts algorithm efficiency and is a core concept in CS courses, FAANG interviews, and graph algorithm design. This set covers space complexity, lookup speed, and when each representation is optimal for sparse vs. dense graphs.

Interactive Deck

5 Cards
1
Front

Adjacency matrix space complexity?

Click to reveal
1
Back

O(V²) — stores an entry for every possible pair of vertices. Efficient for dense graphs but wasteful for sparse ones.

2
Front

Adjacency list space complexity?

Click to reveal
2
Back

O(V + E) — stores only existing edges. Ideal for sparse graphs where E << V².

3
Front

Edge lookup: list vs matrix?

Click to reveal
3
Back
  • Matrix: O(1) — direct index lookup
  • List: O(degree) — must scan neighbors

Matrix wins for frequent edge queries.

4
Locked

When to use an adjacency list?

5
Locked

When to use an adjacency matrix?

Master this topic effortlessly.

Study G helps you master any topic effortlessly using proven learning algorithms and smart review timing

Download Study G

Frequently Asked Questions

What is the difference between adjacency list and adjacency matrix?

An adjacency matrix is a V×V grid storing all edge relationships in O(1), using O(V²) space. An adjacency list stores only existing edges, using O(V+E) space and O(degree) lookup time.

  • Matrix: fast lookup, high memory
  • List: low memory, slower lookup

Which graph representation is better for BFS and DFS?

Adjacency lists are preferred for BFS and DFS because they allow efficient iteration over only existing neighbors. With a matrix, you must scan an entire row (O(V)) even when most edges do not exist.

How much memory does an adjacency matrix use?

An adjacency matrix requires O(V²) space, storing a value for every possible vertex pair. For a graph with 1000 nodes, that means 1,000,000 entries regardless of actual edge count.