AlgoScope

Adjacency List

Data structurebeginnerGraph Representations

For each vertex, a list of its neighbours; compact for sparse graphs.

Decision · step 2 of 8BFS and DFS: Breadth-first from 0
001121345u

Dequeue 0, distance 0. Its adjacency list: 1, 2. New: 1, 2, each at distance 1, enqueued.

Open in the player →or start at step 2

What you will see

The same graph shown as picture and as per-vertex lists; a traversal walks one list at a time.

How bfs and dfs works →

Cost

edge lookupO(deg u)
neighboursO(deg u)
add edgeO(1)
SpaceO(V + E)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.

Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.

Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.

Leads to

Topics that need this one first.

Taught by the same lesson

BFS and DFS covers these too, in the same run.