I can do it in 2 O(n)sweeps if all elements are distinct.
12345
23451

Sweep one to find the 1st element of string 1 in string 2.
Sweep 2 to compare each element of the 2 strings from the position mod n
found in the 1st sweep.

I dont know how to do it if elements are repeated.

but the way Praveen does it is really cool i think.

Sat, Sep 11, 2010 at 1:54 PM, Praveen Baskar <[email protected]>wrote:

> str="hello";
> str1="lloeh";
> if (str+str).subString(str1) is true then the string is cyclic string of
> another
>
>
> On Sat, Sep 11, 2010 at 1:52 PM, bittu <[email protected]> wrote:
>
>> How will you check if a string is cyclic string of another
>>
>> solution O(n)......???/?? or even less compraiosn..
>>
>> --
>> 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.
>>
>>
>
>
> --
> By B. Praveen
>
>  --
> 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