Mid
Trees
DSA & Coding Interviews
How do you find the Lowest Common Ancestor in a BST vs binary tree?
Short answer: BST: walk from root — if both values are smaller go left, both larger go right, else current is LCA. General binary tree: recurse; if both sides return non-null, current is LCA; else return the non-null side.
Complexity
BST average O(h); general tree O(n).
Ask which tree type — the optimal approach changes.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png