Question: Hello, I'm trying to determine the algorithmic complexity of the function below, which determines if a string has been rotated (for example, a string abcd

Hello, I'm trying to determine the algorithmic complexity of the function below, which determines if a string has been rotated (for example, a string "abcd" has been rotated to "bcda"). I believe the following runs in O(n), but I just wanted to verify.

public class Rotate{

public static void main(String[] args) { String first = "abcd"; String second = "cdba";

System.out.println(isRotated(first, second); } private static boolean isRotated(String first, String second){ if(first == null or second == null) {

return false;

} if (first.length == second.length && (first + second).indexOf(str2) > 0) {

return true;

}

return false; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!