Tree Traversal DFS
Height + Depth DFS
Comparison + Validation
Path-Based DFS
Global State + DFS
Tree Construction
Level Order BFS
BST-Specific Patterns
Tree + Graph Conversion
Iterative DFS
patterns:
- DFS (postorder) → compute from children
- DFS (preorder) → pass state downward
- BFS → process levels
- Stack → simulate recursion
- Queue → simulate levels
use DFS when:
- Bottom-up computation (height, diameter)
- Path exploration
- Validation (BST, symmetry)
use BST properties when:
- Sorted order matters
- Searching efficiently
use BFS when:
- Level-based output
- Shortest path in tree
- “View” problems (right/left view)