1. int i=1;

2. while (i <= n) {

3. for (int j=1; j<10; j++)

4. sum++;

5. i++;

6. }

7. for( int j = 1; j <= n; j++ )

8. for( int k = 1; k <= n; k=k*2 )

9. sum++;

1. How many times is statement 4 executed?

A. O(n)

B. O(n2)

C. O(log n)

D. O(n log n)

E. none of the above

Here I chose A

2. How many times is statement 9 executed?

A. O(n)

B. O(n2)

C. O(log n)

D. O(n log n)

E. none of the above

Because of line 8 (k=k*2) I chose C

3. What is the running time of the entire code fragment?

A. O(n)

B. O(n2)

C. O(log n)

D. O(n log n)

Since O(n)+O(logn)=O(n) so I chose A

What do u think?