Yes, my bad. I din notice the recursion at all! Thot it to be a flat
mid-split followed by a reverse followed by a concat. Thanks.

On Mon, Nov 26, 2012 at 11:18 PM, atul anand <[email protected]>wrote:

> considering '+' , here will take Cn time . Here '+' is for concatenate ,
> now this concatenation taking place in constant time?? , i dont think
> so..internally it will be adding elements to new m/m space and for that it
> need to traverse each character...so it will take cn time.
> so T(n) =T(n/2) + cn =  nlogn
>
>
> On Tue, Nov 27, 2012 at 11:17 AM, shady <[email protected]> wrote:
>
>> what is the time complexity of this?
>>
>> str_reverse(str){
>>     if(isempty(str)) return str;
>>     else if(length(str) = even) then split str into str_1 and str_2; (of
>> equal length)
>>            return str_reverse(str_2)+str_reverse(str_1);
>>     else split str into str_1, str_2, str_3; //if str is odd length, e.g.
>> len = 7, split by 1-3 | 4 | 5-7
>>           return str_reverse(str_3)+str_2+str_reverse(str_1);
>> }
>>
>> --
>>
>>
>>
>
>  --
>
>
>

-- 


Reply via email to