AlgoScope

DFS Recursive

AlgorithmbeginnerGraph Traversal

The natural recursive form; each call frame is one vertex, and the current path is the call stack.

Decision · step 2 of 15DFS Checks: Recursive DFS and its call stack
0123456u

Call dfs(0): mark it seen, visit number 1. Neighbours 1, 2. 1 is unseen, so the call dives into it before looking at the rest.

Open in the player →or start at step 2

What you will see

Frames stack up on the way down and pop on backtrack.

How dfs checks works →

Cost

BestO(V + E)
AverageO(V + E)
WorstO(V + E)
SpaceO(V)

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, predict what happens next, try operations in any order.

Screen readers: Vertices announce name, neighbours and state (in queue, visited, current); each step announces which vertex is processed and which neighbours are discovered.

Reduced motion: Frontier and visited changes are crossfades; the traversal edge is emphasized without a travelling token.

A variant of

Taught by the same lesson

DFS Checks covers these too, in the same run.