For BST it would be rather simpler. find the first node which lies in
between the two.

On Wed, Nov 16, 2011 at 1:44 PM, anshu mishra <anshumishra6...@gmail.com>wrote:

> Node *LCA(node *root, node *e1, node *e2, int &x)
>
> {
>
>                 Node *temp =NULL;
>
>                 Int y = 0;
>
>                 If (root->left) temp = LCA(root->left, e1, e2, y);
>
>                 x+=y;
>
>                 if (temp) return temp;
>
>                if (x==2) return node;
>
>                 y = 0;
>
>     If (root->right) temp = LCA(root->right, e1, e2, y);
>
>                 x+=y;
>
>                 if (temp) return temp;
>
>                 if (x==2) return node;
>
>                 If (root == e1 || root == e2) x++;
>
>                 Return null;
>
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to