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

Understanding the Execution Order of Logic in Binary Tree Recursion

The placement of code within a recursive function significantly impacts how the program interatcs with the state of a binary tree. This is particularly evident when using external or persistent variables to track the relationship between different nodes during traversal. Impact of Early Assignment When calculating the minimum absolute differenc ...

Posted on Sun, 07 Jun 2026 18:17:22 +0000 by djsl

Recovering and Validating Binary Search Trees

Recovering a Swapped Binary Search Tree A binary search tree (BST) has two of its nodes swapped by mistake. The task is to restore the tree to its correct BST form without altering its structure. The challenge is to achieve this with constant space complexity (O(1) space), avoiding the use of a full in-order traversal list. Approach The key obs ...

Posted on Thu, 14 May 2026 13:38:34 +0000 by John_S