English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How to test, if two circular strings are identical?
We always take strings of equal length 'n'
for example like "helloworld" and "elloworldh"

any ideas to show that checks they are identical?
how i should proceed in designing a algorithm.if O(n) complexity is obtained how ?

2006-11-09 04:47:20 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

You are given two strings, lets say string1 and string2.

Get the first letter of string one, straing1[0] and find this letter in string2.

for(iny i = 0;i<=len(string2);i++)
if(strring1[0] == strring2[i]) return i;
return -1;

Now that you know the position of first letter, in second string. Go on comparing the letters from this positions.
It may possible that the first letter ocuurs twice in the string. So you should repeat the whole process, till all the occurances of first letters are done.
At the first stage itself you can find out all the positions in the second string where first letter occured. Now for the second loop, you will always start comparing from that position.

2006-11-09 15:53:30 · answer #1 · answered by manoj Ransing 3 · 0 0

use a for loop starting at 0 to string length. Then use the string index of the first string at the index of the loop, and the string index of the second string at length of string - the index of the for loop. Then you need an if statement to test if they are equal to each other (the letters at those two index of the strings). You will need a variable that is a bool that turns false if the letters are mitchmatched, or if the lengths of the strings don't equal each other.

2006-11-09 14:03:05 · answer #2 · answered by scott p 3 · 0 0

fedest.com, questions and answers