BFS and DFS in Java: A Visual Guide
Learn BFS and DFS with static graph, queue and call-stack traces, tested Java, shortest paths, grids and 12 practical question patterns.
Read article →Build the mental model and learn the reusable implementation pattern.
Learn BFS and DFS with static graph, queue and call-stack traces, tested Java, shortest paths, grids and 12 practical question patterns.
Read article →Use the core idea in a direct problem with one main decision.
Combine the pattern with boundaries, state, or another technique.
Work through problems with less obvious invariants and tighter constraints.
Follow BFS or DFS while the frontier and visited set make every decision visible.
Keyboard: focus this simulator, then use ← → to step, Home End to jump, Space to play or pause, and R to reset.