@Gene...BFS wont work i guess. Because even if y is in the path it may not be in the queue. DFS is a bit intuitive i guess....
On Sat, Jan 8, 2011 at 4:32 PM, Gene <[email protected]> wrote: > The problem never says that the tree is rooted. So LCA is not > very relevant. > > The path between two nodes in any tree is unique. (Otherwise it has a cycle > and is not a tree.) So all that's needed is to search for z starting at x > (DFS or BFS will work fine). When you find the unique path, see if it > contains y. This is O(n) where n is the number of nodes. > > The problem is more interesting if you are allowed to pre-process the tree > one time in order to build a data structure to support many queries. > > > > -- > 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%[email protected]> > . > 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.
