All Topics

Trees & BST

Hierarchical structures — traversals, path problems, LCA, and balanced BST operations

0/50 solved

Tree Traversals (BFS/DFS)

Master inorder, preorder, postorder, and level-order to unlock all tree problems

O(n) O(n)

Approach

BFS: Use a queue, process level by level. DFS: Use recursion or stack. Inorder (left-root-right) gives sorted order for BST. Preorder (root-left-right) for tree serialization. Postorder (left-right-root) for deletion and evaluation.

How to Recognize

1

Problem asks to visit nodes in a specific order

2

Need level-by-level processing (BFS) or depth-first exploration (DFS)

3

Phrases like 'zigzag level order', 'right side view', 'boundary traversal'

4

Need to collect nodes at specific depths or in specific sequences

Pro Tips

BFS uses a Queue; DFS uses recursion or an explicit Stack

For zigzag, alternate the direction of insertion at each level

Iterative inorder using a stack is the foundation for BST iterator design

10

Total

6

Easy

4

Medium

0

Hard

Time

O(n)

Space

O(n)