← back to algorithms

dedicated visualizer

Depth-First Search

Follows one branch as deeply as possible before backtracking to try the next branch. This page keeps the runner, chart, and controls focused on a single algorithm so the walkthrough feels calmer than the overview page.

graphsintermediatebest O(V + E)worst O(V + E)space O(V)
stackbacktrackingdeep traversal

session controls

Compare this algorithm against a related one, turn on quiz mode, or keep the current state in a shareable URL.

current shareable URL

Copy the URL to preserve this exact dataset, target, compare mode, and quiz state.

browse more

Want a different problem or visual mode? Jump back to the catalog and open another dedicated page.

open catalog

scenario presets

Load a focused input that reveals a specific behavior quickly instead of hand-editing every value first.

graph controls

Graph algorithms reuse the same learning graph so you can compare traversal and shortest-path behavior side by side.

graph note

BFS and DFS emphasize traversal order. Dijkstra adds weighted relaxations and a cost-aware final route.

step 1 / 130% complete

current action

push start

stack

A

current node

none

run summary

Finished in 13 steps. G is the target node, so DFS stops here.

visited

5

stack

2

frontier

2

steps

13

final route

A → B → D → E → G

current explanation

Depth-first search starts by pushing A onto the stack.

simple explanation

DFS dives down one path at a time using a stack.

pseudocode

1push the start node
2pop the top node and inspect it
3return if it is the target
4push each undiscovered neighbor
5repeat until the stack is empty

complexity card

best

O(V + E)

average

O(V + E)

worst

O(V + E)

space

O(V)

algorithm notes

intuition

DFS commits to one path until it cannot go any deeper, then backtracks.

tradeoffs

  • Good for path existence and topological-style reasoning.
  • Does not guarantee the shortest path.
  • Can be implemented recursively or iteratively.

when to use it

Use when you want deep traversal behavior, backtracking, or graph structure analysis.

interview tips

  • Clarify whether you mark nodes when pushing or when popping.
  • Use DFS to discuss connected components and cycle detection.

what I learned building this

typed definitions

One algorithm schema now drives the catalog, counters, pseudocode, notes, and visual modes, which keeps the UI consistent as the lab grows.

replay over mutation

Precomputed steps made it much easier to synchronize explanations, metrics, quiz prompts, and scrubber playback without hidden state drifting out of sync.

portfolio framing

Shareable URL state, compare mode, and responsive layouts mattered as much as the algorithm logic because this page needs to teach clearly and still feel polished as a product.

more in this lane

Want a different take on the same problem family? These stay in the same category but change the strategy.