I'm a little new to complexity, and was trying to determine the algorithmic complexity of the process below, which calculates whether a given string is a rotation of another given string (i.e., if "bcdea" is a rotation of "abcde"). I'm pretty sure this breaks down to O(n), as each check in the function breaks down to n at worst (I think!). Does that sound about right?
public class Rotate {
public static void main(String[] args) {
String str1 = "abcde";
String str2 = "bcdea";
System.out.println(isRotation(str1, str2));
}
public static boolean isRotation(String str1, String str2) {
if(str1 == null || str2 == null){
return false;
}
System.out.println(str1 + str2);
if(str1.length() == str2.length() && (str1 + str2).indexOf(str2) > 0){
return true;
}
return false;
}
}