PathfindingD1Phase 1traversalstackexploration

Depth-First Search

Depth-prioritized traversal useful for connectivity and structure discovery.

Easy Explanation

DFS explores one path deeply before backtracking, which is useful for full traversal and structure discovery.

Renderer Mode

`Simple` uses abstract, short-form-friendly visuals. `Advanced` keeps the current detailed view.

Arrays + Grid
Visualizer
O(V + E)DFS
Deterministic depth-first traversal on a grid with stack pushes, visits, neighbor checks, and backtracking.

Grid

n/a

Visited

0

Depth

n/a

Result

Searching

Safe mode: choose a tool to edit the grid.

Ready

Press Play or Step to start execution.

No DFS run available for visualization.
Legend: S/T start/target, # blocked, stack (cyan), visited (blue), current (amber), path (green), inspect (red/orange/violet).
Depth-First Search Implementation
Pseudocode + TypeScript
Reference implementation examples are intentionally abstracted from the playback engine so learners can map concepts to code.
pseudocode
function dfs(graph, start, target):
  stack <- [start]
  visited <- { start }
  parent[start] <- none

  while stack is not empty:
    node <- pop(stack)

    if node == target:
      return reconstruct_path(parent, target)

    for neighbor in neighbors(node):
      if neighbor not in visited:
        visited.add(neighbor)
        parent[neighbor] <- node
        push(stack, neighbor)

  return no path
1.00xNo Run