A-Level · Graph Traversal

DFS pop order <12-node graph>

Starting at A, neighbours taken in alphabetical order. Watch when each node is pushed (discovered) versus when it's popped (finished) — they are very different sequences.

A B L G K H D I F C E J Stack unvisited visited current

Adjacency list (Python dictionary)

graph = {

The current node's entry is highlighted. DFS simply reads its neighbours left to right — green = already visited (skipped), white = unvisited (taken next).

Adjacency matrix

Same information, matrix form: read the highlighted row left to right and take the first 1 whose column isn't green yet.

Ready. All nodes unvisited, stack empty.
Visit (push) order: —
Pop order: —
1 step/s
Step 0 / 24

Keyboard: ← → to step  ·  Space to play/pause  ·  R to reset