Hi..
Think Ur Algo Will work only when u and v are at equal height frm
their Common ancestor 'P'
So U need to think of all possibilities
Node* ClosestCommonAncestor(Node* u, Node* v)
{
if(! u && v )
return NULL;
if( u == v)
return u->parent;
x = ClosestCommonAncestor(u->par,v);
y = ClosestCommonAncestor(u->par,v->par);
z = ClosestCommonAncestor(u,v->par);
return (x || y ||z) ;
}
Some terminal condn needs to be checked...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---