← Back to All Algorithms

🔍 Depth-First Search (DFS)

How It Works

DFS explores as deep as possible before backtracking, using a stack (or recursion):

  1. Start from source, push to stack
  2. Pop a vertex, mark as visited
  3. Push all unvisited neighbors to stack
  4. Repeat until stack is empty

Uses: Cycle detection, topological sort, connected components, path finding

Click "Start" to run DFS from node A