Patterns
TD · Pattern 08
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
Spot it when
- Root-to-leaf path sums
- Max/min depth
- Validate BST properties
- All paths from root to leaf
Problems
Easy to hard · 0/11 solved
#112Path SumEasy#113Path Sum IIMedium#104Maximum Depth of Binary TreeEasy#543Diameter of Binary TreeEasy#98Validate Binary Search TreeMedium#124Binary Tree Maximum Path SumHard#235Lowest Common Ancestor of BSTMedium#236Lowest Common Ancestor of Binary TreeMedium#230Kth Smallest Element in a BSTMedium#297Serialize and Deserialize Binary TreeHard#99Recover Binary Search TreeHard