Visualize LCA in a BST step by step. Watch the algorithm walk toward the split point where p and q diverge, with no recursion or parent pointers needed.
The LCA of two nodes p and q is the deepest node that has both p and q as descendants. In a BST this can be found in O(h) without extra storage.
In a BST: if both p and q are less than the current node, their LCA must be in the left subtree. If both are greater, it is in the right subtree.
Keep walking left or right as long as both values are on the same side. Mark each bypassed node as visited.
The first node where p and q "split" (one on each side, or one equals the node) is the LCA. Return immediately.
We traverse at most one root-to-leaf path. In a balanced BST that is O(log N). No recursion stack or parent pointers needed.
LeetCode 235. For a general binary tree (not BST) LCA requires O(N) DFS. The BST version is faster because it exploits the ordering property.