A loop <code>for (int i = 1; i < n; i *= 2)</code> has time complexity
- A
O(n²)
- Bcheck_circle
O(log n)
- C
O(n)
- D
O(1)
Explanation
i doubles each iteration; runs about log₂(n) times.
AP Computer Science A· difficulty 4/5
A loop <code>for (int i = 1; i < n; i *= 2)</code> has time complexity
O(n²)
O(log n)
O(n)
O(1)
Explanation
i doubles each iteration; runs about log₂(n) times.
Want 10 more like this — adaptive to your weak spots?
What does this print? <codeint x = 0; for (int i = 0; i < 5; i++); x++; System.out.println(x); </code</pre…
chevron_rightWhat is the final value of x? <codeint x = 1; for (int i = 1; i <= 3; i++) x = 2; </code</pre…
chevron_rightAdding O(n) and O(n²) gives…
chevron_right