Trees and Binary Search
Recursive hierarchical structures used in traversal-based problems, dynamic state management, and ordered data lookup. Binary Search leverages sorted structure or monotonic properties for O(log n) operations.
1.0 Tree Fundamentals and Traversals
- Inorder / Preorder / Postorder (recursive + iterative)
- Level-order (BFS using queue)
- DFS vs BFS trade-offs
2.0 Binary Search Tree (BST) Patterns
- Validate BST structure
- Floor / Ceiling / Closest value
- Kth smallest/largest element
- Range queries in BST
3.0 Binary Tree Recursion Patterns
- Subtree checking and symmetry
- Path sum variations (root-to-leaf, any-to-any)
- Diameter and max depth
- LCA (Lowest Common Ancestor)
4.0 Tree Construction and Serialization
- Build tree from inorder + preorder/postorder
- Serialize/deserialize binary trees (DFS/BFS)
- Flatten binary tree (in-place)
5.0 Binary Search Patterns (On Arrays)
- Standard binary search (left/right bounds)
- First/last occurrence (duplicates allowed)
- Search in rotated array
- Search on answer space (e.g., min capacity to ship packages)
6.0 Binary Search on Monotonic Functions
- Find smallest/largest x such that f(x) is valid
- Application in greedy/DP problems
- Lower bound / upper bound logic
7.0 Segment Trees and Advanced Structures
- Range query/update (RMQ, RSQ)
- Lazy propagation
- Binary Indexed Tree (Fenwick Tree)
8.0 N-ary Trees and Generalized Trees
- Generic tree traversal (DFS/BFS)
- M-ary trees, Trie basics
- Folder/tree structure parsing
9.0 Tree to Graph Transitions
- Convert tree to graph for bidirectional traversal
- BFS/DFS in tree-turned-undirected-graph
10.0 Special Mentions
- Morris Traversal (O(1) space inorder)
- Tree diameter via post-order
- Threaded trees
- Binary lifting (ancestor queries)
- Sparse tables