What's the big-O time complexity of the two methods listed below?
Is method 1 O(log n²)
or O(log n)
?
Is method 2 O(n²)
or something else?
public static void method1(int n) {
int k = 0;
for (int i = 1; i <= n; i = i*2)
for (int j = n; j > 1; j = j/2)
k++;
}
public static void method2(int n) {
for (int i = 1; i <= n; i = i + 1)
for (int j = i; j <= n; j++)
method1(n);
}