2026-02-01 · 10 min read

Complete DFS Guide for Coding Interviews

Depth-first search patterns: trees, graphs, backtracking, and pitfalls.

Complete DFS Guide

DFS is the workhorse for trees, graphs, and backtracking.

Templates

  • Recursive tree DFS
  • Graph adjacency list DFS with visited set
  • Backtracking with choose / explore / unchoose

Practice: Number of Islands, Clone Graph.