Depth-First Search
Interactive lab
Try it: Depth-First Search
How depth-first search explores one path as far as it can before backtracking, using the call stack of recursive calls.
How it works
- Visit the start node and mark it.
- For each neighbour in order, if it is unvisited, recursively visit it — the current call waits.
- When a node has no unvisited neighbours, its call returns: backtrack.
- Nodes never reached are not connected to the start.
Default run (32 steps): Start DFS at A: follow one path as deep as it goes before backing up. … DFS finished. Visit order: A → B → C → F → E → D → G. Unreachable from A: H.
Simplified: Fixed 8-node undirected graph; you choose which edges exist and can drag nodes around (the layout never affects the algorithm).
Educational simulation
Loading the simulation…