Neco 2021 Computer Studies Question 35

Practice objective / multiple choice question 35 from the 2021 Neco Computer Studies examination.

Neco 2021 Computer Studies Objective / Multiple Choice Medium Difficulty
Question 35 NECO • 2021 • COMPUTER_STUDIES • objective

Consider the following two code fragments that each compute the sum of a series of integers.\nFragment A:\n\[\text{for } i = 1 \text{ to } n \\ \quad \text{for } j = 1 \text{ to } i \\ \quad\quad \text{sum} = \text{sum} + 1\]\nFragment B:\n\[i = 1; \\ \text{while } i \le n \\ \quad \text{sum} = \text{sum} + i; \\ \quad i = i \times 2;\]\nAssuming each execution of the innermost statement \(\text{sum} = \text{sum} + 1\) or \(\text{sum} = \text{sum} + i\) counts as one primitive operation, express the total number of primitive operations performed by each fragment as a function of \(n\). Then state which fragment has the lower order of growth (Big‑O notation).

Answer Options

A. Fragment A: n^2 operations (O(n^2)); Fragment B: log_2 n operations (O(log n)); Fragment B grows slower
B. Fragment A: n(n-1)\/2 operations (O(n^2)); Fragment B: floor(log_2 n) operations (O(log n)); Fragment B grows slower
C. Fragment A: n(n+1)\/2 operations (O(n^2)); Fragment B: n operations (O(n)); Fragment A grows slower
Correct Answer D. Fragment A: n(n+1)/2 operations (O(n^2)); Fragment B: floor(log_2 n) + 1 operations (O(log n)); Fragment B grows slower
Correct Answer
D
Correct Option:
Fragment A: n(n+1)/2 operations (O(n^2)); Fragment B: floor(log_2 n) + 1 operations (O(log n)); Fragment B grows slower

About This Question

This is Neco 2021 Computer Studies Question 35. It is one of the objective questions from the 2021 Neco Computer Studies examination.

Difficulty level: Medium .

Master the Exam!

You've seen a preview, but there are thousands more questions plus AI tutor to break down complex solutions.

Unlock Full Access Available for Android & Windows
Chat with Support