algorythms
All Patterns
Pattern 8

Tree DFS

Tree DFS

Explore tree paths using recursion (or explicit stack). Three traversal orders: pre-, in-, post-order. Great for path sums and BST validation.

Time

O(n)

Space

O(h) where h = height

Recognize it when

  • Root-to-leaf path sums
  • Max/min depth
  • Validate BST properties
  • All paths from root to leaf
Progress0/11
0 solved0 attempted