Nested Loop Time Complexity
Determine the overall time complexity of the nestedDoublingLoop method.
public void nestedDoublingLoop(int n) {
for (int i = 1; i < n; i *= 2) {
for (int j = 0; j < i; j++) {
System.out.println(i + j);
}
}
}
A
O(log n)
B
O(n^2)
C
O(n)
D
O(n log n)
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE