Reversing a string should be linear time.

void reverse(char *str)
{
   int i = 0;
   int j = strlen(str)-1;
   while(i < j)
      swap(str[i++], str[--j]);
}

On Nov 27, 12:47 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