u can maintain the size..
and if you don't want that , at least memoize it.. it won't be O(n^2) then.

Rohit Saraf
Sophomore
Computer Science and Engineering
IIT Bombay


On Wed, Dec 9, 2009 at 9:12 PM, chitta koushik
<[email protected]>wrote:

> Though i couldn't get both ur approaches clearly , guess 2nd approach shud
> take O(n^2)  since you go to each node and find the size of left subtree .
>
> Or i shud be missing something. my bad can you explain your approaches
> clearly.
>
> On Wed, Dec 9, 2009 at 8:20 PM, Rohit Saraf 
> <[email protected]>wrote:
>
>> do it iteratively either by:
>>
>> 1) If size of left tree is less than k, rotate the tree left. and so on
>> till .....single while loop required for this.
>> or
>> 2) Start from head, if k is more than size of left-tree, go to left and
>> continue searching.. other wise go right and search for k-size(left)-1 in
>> right tree. All this can be implemented in a single while loop.
>>
>>  --
>> 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.
>

--

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