DFS Recursive
The natural recursive form; each call frame is one vertex, and the current path is the call stack.
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.
What you will see
Frames stack up on the way down and pop on backtrack.
Cost
| Best | O(V + E) |
|---|---|
| Average | O(V + E) |
| Worst | O(V + E) |
| Space | O(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.
Before this
A variant of
Taught by the same lesson
DFS Checks covers these too, in the same run.