Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

0 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 (8k points)

1 Answer

0 votes

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 (8k points)
...