my solution will not work..it works only if X & Y or on the same side of subtree..like suppose if path is left node,root,right node..then the LCS will do..i think first we need to find whether both X & Y r on the both side of subtree or different sides..depending on tht we need to find the path and Y..sorry for multiple posts..
On Jan 8, 3:18 am, Newbie <[email protected]> wrote: > small correction in my post.. > > > > > > > > > yes..DFS seems a good solution..then look until u get a Z..here is a > > piece of code.. > > > 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.
