Start from the root and do a breadth first traversal until you hit x
or Z...

Once you have x or Z, treat that node as root and traverse breadth
first on that sub-tree till you reach the other node (i.e, if you hit
X first, see if you can reach Z from X)... At the same time, if you
encounter Y during the sub-tree traversal and you indeed hit Z at some
point, return true.

On Jan 6, 11:00 am, Decipher <[email protected]> wrote:
> There is a binary tree(Not a BST) in which you are given three nodes
> x,y,z .Write a function which finds whether y lies in the path b/w x
> and z.

-- 
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?hl=en.

Reply via email to