I have this example algorithm:
int sum = 0;
int j = 1;
while (j <= n) {
sum++;
j = j * 2;
}
The book I am reading, "Building Java Programs - a Back to the Basics Approach" tells me that I need to find this:
Approximate the runtime of the following code fragment, in terms of n: Write your answer in a format such as O(N^2) or O(N log N).
I don't seem to understand how to get from point a to point b here. I figured two statements = O(2), and a loop with two statements = O(2N) so it should be O(2N + 2). Where am I going wrong?