tag root as 0 , tag left child as 00 ,  right child as 01.
left child's left child as 000 , left's child's right child as
001 ...  and so on.
now
let input be tags t1 and t2
if( (t1 == (t2>>1)) || (t2==(t1>>1)))
return child parent relationship
if( (t1 == (t2>>2)) || (t2==(t1>>2)))
return child grand-parent relationship
On Jan 28, 5:10 am, Nirmal <nirm...@gmail.com> wrote:
> I found this problem in one of the interview form, that it is interesting to
> discuss
>
> Problem :
>
> There are two nodes given in a tree(not binary tree). Find whether one node
> is parent/grand parent of other.
> order should be O(1).
>
> You are allowed to do any amount of preprocessing ....

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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