In essence what you say boils down to DFS , isnt it ?

On Sat, Jan 8, 2011 at 10:15 PM, Algoose chase <harishp...@gmail.com> 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 <gene.ress...@gmail.com> 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 algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> 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 algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to