I am not clear about the definition.Plz confirm in case one node is parent
of other then whether that parent node is ancestor or it is -1.And plz
confirm above code if it miss any case


On Mon, Apr 22, 2013 at 1:13 AM, Dave <dave_and_da...@juno.com> wrote:

> @Rahul: You must know if a node is its own ancestor or not. This is a
> matter of definition.
>
> If a node is its own ancestor, and if n1 is an ancestor of n2, then n1 is
> the least common ancestor of n1 and n2.
>
> If a node is not its own ancestor, and if n1 is an ancestor of n2, then
> the parent of n1 is the least common ancestor.
>
> It seems that common usage is that a node is its own ancestor; see, e.g.,
> http://en.wikipedia.org/wiki/Lowest_common_ancestor.
>
> Dave
>
> On Sunday, April 21, 2013 11:56:01 AM UTC-5, rahul sharma wrote:
>
>> int leastCommanAncestor(struct node* root, int n1, int n2)
>> {
>>  if(root==NULL)
>>  return -1;
>>  if(root->data>n1 && root->data>n2)
>>  return leastCommanAncestor(root->**left,n1,n2);
>>  else if(root->data<n1 && root->data<n2)
>>  return leastCommanAncestor(root->**right,n1,n2);
>>  return root->data;
>>
>> }
>>
>> Does this code miss any case?N suppose if we have to find LCA of n1 and
>> n2 and suppose n1 is parent of n2 ..then this will return n1..is this fyn
>> or if n1 is parent of n2 then we should return -1??
>>
>> Plz. comment
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to