Binary Search Tree Operations: Lowest Common Ancestor, Insertion, and Deletion
Lowest Common Ancestor in a BST (LeetCode 235)
Given a BST and two nodes p and q, find their lowest common ancestor (LCA). The BST property allows an efficient traversal from root down: the LCA is the first node whose value lies between p->val and q->val (inclusive). Because the tree is ordered, moving left/right narrows down the range un ...
Posted on Wed, 26 Aug 2026 16:29:53 +0000 by Bogart
Finding the Lowest Common Ancestor in Binary Trees
Core Approach1. Base Cases:If the current node is null, return nullIf the current node matches either target, return the current node (a node is its own ancestor)2. Recursive Search:Recursively search the left subtree, storing the resultRecursively search the right subtree, storing the result3. Result Analysis:If both left and right results are ...
Posted on Mon, 11 May 2026 08:08:11 +0000 by enoyhs