BST [mp]
Micro pattern¶
Description¶
Exploit the invariant that left-subtree keys are smaller and right-subtree keys are larger than the current key.
Problems¶
Ordered search and maintenance¶
Use key comparisons to choose a subtree and maintain its ordering.
- AVL trees (DSA)
- 669. Trim a Binary Search Tree (Google Prep)
Validate ordering¶
Propagate strict ancestor bounds or check increasing inorder values.
- 98. Validate Binary Search Tree (Top Easy)
Construct or enumerate in sorted order¶
Select ordered roots or traverse keys in ascending order.
- 108. Convert Sorted Array to Binary Search Tree (Top Easy)
- 230. Kth Smallest Element in a BST (Top Medium)
- 96. Unique Binary Search Trees (Dynamic Programming)
- 95. Unique Binary Search Trees II (Dynamic Programming)