Neco 2021 Computer Studies Question 35
Practice objective / multiple choice question 35 from the 2021 Neco Computer Studies examination.
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
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.