Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+4 votes

Here's the question that Sam asked about. The quiz allowed one of two possible answers, but only one is really correct.

int count = 0;
for (int i = 0; i < n; i++){
     for (int j = 0; j < 100000; j++){
          count++;
     }
}
count++;
count++;
asked in CSC371 by (1 point)

1 Answer

+1 vote

The ONE correct answer is O(n). Because the inner loop executes a constant number of times, its execution is not dependent on the value of n. Therefore, the answer is O(n) because of the outer loop. Now in Moodle, the only correct answer accepted is O(n).

As far as your score, if you answered O(n^2), I'm not reducing your score, but you should understand why O(n^2) is not correct.

answered by (1 point)
...