This post is about finding the lowest common ancestor of 2 nodes in a binary search tree.
Lowest Common Ancestor of 2 nodes x and y is the node that has both x and y as its desendents. The below image is might help you to understand the above statement.
You might also be interested in
Binary Search Tree in Python
Binary Search Tree in C++
Height of Binary Search Tree
Insert ,Search and Display Binary Search Tree
Leaf Nodes of Binary Search Tree
Minimum and Maximum Elements in BST
Lowest Common Ancestor of 2 nodes x and y is the node that has both x and y as its desendents. The below image is might help you to understand the above statement.
In this tree, the lowest common ancestor of the nodes x and yis marked in dark green. Other common ancestors are shown in light green. |
If you want to know more about Lowest Common Ancestor click here.
To see more programs about BST and other Data Structures click here
C++ Program
Sample input and output to check the program
You might also be interested in
Binary Search Tree in Python
Binary Search Tree in C++
Height of Binary Search Tree
Insert ,Search and Display Binary Search Tree
Leaf Nodes of Binary Search Tree
Minimum and Maximum Elements in BST
Comments
Post a Comment