Make delicious recipes!

Given 2 nodes in a tree, find common ancestor

Common ancestor is that node which contains one given node in its left subtree and another node in right subtree. There will be only one such node. Rest all ancestors will have both the nodes in either right or left subtree but not one in each.



Good part of the above algorithm is that works even when both the nodes are in the same path (i.e. one node is some grandchild of other node)




Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal