yes..DFS seems a good solution..then look until u get a Z..here is a
piece of code..

static ArrayList<Integer> buffer;
void findSum(TreeNode head, Node nodeZ,ArrayList<Integer> buffer) {

if (head == null || head == nodeZ) return;

buffer.add(head.data);

ArrayList<Integer> c1 = (ArrayList<Integer>) buffer.clone();
ArrayList<Integer> c2 = (ArrayList<Integer>) buffer.clone();

findSum(head.left, nodeZ, c1);
findSum(head.right, nodeZ, c2);

}

then look thu the arraylist to check see if the Y is there..Hope this
helps..correct me if I'm wrong..

On Jan 8, 12:12 am, nishaanth <[email protected]> wrote:
> How about this solution, Do a DFS on the graph with x as the start node.
>
> If you get z , just see if y is in the stack, if its there then it is in the
> path,else it is not.
>
> correct me if i am wrong.
>
> On Fri, Jan 7, 2011 at 7:51 PM, juver++ <[email protected]> wrote:
> > Heh, problem clearly stated that there a general binary tree, not BST.
>
> > --
> > 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]<algogeeks%2bunsubscr...@googlegroups 
> > .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> S.Nishaanth,
> Computer Science and engineering,
> IIT Madras.

-- 
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