LearnViz CompSci
Home / Learn / Data Structures / Adjacency List

Intermediate Topic 28 of 52 Data Structures

Adjacency List

Graph storage keeping each vertex's neighbors in a list.

How it works

An adjacency list gives each vertex a list of its neighbors, using O(V + E) memory. Iterating over a vertex's neighbors costs only its degree, which makes traversals such as BFS and DFS run in O(V + E). Checking whether a specific edge exists takes O(degree) unless neighbors are stored in a hash set. Weighted graphs store pairs of neighbor and weight.

Step-by-step walkthrough

  1. Each vertex stores a list of its neighbors.
  2. A lists B and C.
  3. A also lists C.
  4. C lists D, so edges are stored only where they exist.
  5. Memory is O(V + E), ideal for sparse graphs.

Where it is used

Sparse graphs such as road networks, social graphs, dependency graphs and web link graphs are stored as adjacency lists. Most graph libraries and competitive-programming solutions use this form.

Common pitfall

For undirected graphs each edge must be added in both lists, and forgetting one direction is a classic bug. Vertex numbering must match list indexes. Dense graphs waste time scanning long lists; an adjacency matrix may be better there. Avoid duplicate entries.

Where it fits in the course

Adjacency List is topic 28 of 52 in Data Structures, rated Intermediate. It follows Graphs. The next topic is Adjacency Matrix.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Data Structures quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Adjacency List?
Graph storage keeping each vertex's neighbors in a list. It belongs to Data Structures and is an intermediate-level topic.
Where do people use Adjacency List?
Sparse graphs such as road networks, social graphs, dependency graphs and web link graphs are stored as adjacency lists.
What is the most common mistake with Adjacency List?
For undirected graphs each edge must be added in both lists, and forgetting one direction is a classic bug.
What should I learn before this topic?
Start with Graphs, the topic just before it in Data Structures.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Data Structures quiz.
Is Adjacency List hard to learn?
It is an Intermediate topic. Be comfortable with the Beginner topics in this area first, then read the common pitfall carefully, since it is where most mistakes happen.
How long does it take to learn Adjacency List?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Adjacency List?
Graphs, Adjacency Matrix, Fenwick Trees are closely connected. The full list is in the related topics section of this page.
What should I study after Adjacency List?
Continue with Adjacency Matrix, the next topic in Data Structures.

Related topics