Each of the four Java functions given here returns a string of length n whose characters are all x. Determine the order of growth of the running time of each function. Recall that concatenating two strings in Java takes time proportional to the length of the resulting string.
public static String method1(int n){ if (n == 0) return ""; String temp = method1(n / 2); if (n % 2 == 0) return temp + temp; else return temp + temp + "x";}public static String method2(int n){ String s = ""; for (int i = 0; i < n; i++) s = s + "x"; return s;}public static String method3(int n){ if (n == 0) return ""; if (n == 1) return "x"; return method3(n/2) + method3(n - n/2);}public static String method4(int n){ char[] temp = new char[n]; for (int i = 0; i < n; i++) temp[i] = 'x'; return new String(temp);}
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.