DSA Pattern: Depth First Search
DFS for graph and tree traversal
Pattern Overview
When to Use
- Tree traversals
- Path finding
- Cycle detection
- Connected components
Benefits
- Natural recursion
- Stack-based iterative
- Memory O(h) for trees
- Explores deep paths first
Example Problems
Number of Islands
DFS on 2D grid
Path Sum in Binary Tree
Root to leaf DFS
Clone Graph
DFS with visited map
Practice Exercises
Step-by-step solutions, code implementations, and visualization diagrams will be available here soon.