**Problem link:** http://www.geeksforgeeks.org/lowest-common-ancestor-in-a-binary-search-tree/

**Problem Statement:**

Given values of two nodes in a Binary Search Tree, write a c program to find the Lowest Common Ancestor (LCA). You may assume that both the values exist in the tree. You can assume that the nodes are present in the tree.

**Solution Idea:**

By the definition of BST, all nodes in the left sub-tree is smaller than the root, and all elements of the right sub-tree is greater than the root. So, if we start from root, if root is in between the input nodes then root is the answer, otherwise both input nodes are part of left sub-tree or both are parts of right sub-tree. We perform this operation recursively.

**Solution Gist:**

### Like this:

Like Loading...

*Related*

Tagged: binary-search-tree, binary-tree, C, memory-allocation, mid-level, pointers, recursion, tree

## Leave a Reply