In essence what you say boils down to DFS , isnt it ? On Sat, Jan 8, 2011 at 10:15 PM, Algoose chase <[email protected]> wrote:
> Will this work ? > > Find the node x, then the node y within the sub tree rooted at x and then z > within the sub tree rooted at y since they must within a unique path > If any of those searches fails there are no such nodes > > > On Sun, Jan 9, 2011 at 6:02 AM, 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. >> > > -- > 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.
