Lowest Common Ancestor
Walk down while both values are on the same side. Where they split is the answer.
BST Queries: Lowest common ancestor
Both 20 and 40 are smaller than 50, so both live to the left. Go left.
Cost
- Best
- O(1)
- Average
- O(log n)
- Worst
- O(n)
- Space
- O(1)
Before this
Taught by the same lesson
BST Queries covers these too, in the same run.