Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 1(v)

1 mark

Computer ScienceISC 2026 Improvement Computer Science Paper 1MCQComplexity and Big O notation

Choose the correct option.

The worst-case complexity for following code segment is: for (int i = 0; i < p; i++) { a +=…

The worst-case complexity for following code segment is:
for (int i = 0; i < p; i++)
{
    a += Math.sqrt(i);
}
for (int j = 0; j < q; j++)
{
    b += Math.log(j + 1);
}
  • (a)$O(1)$
  • (b)$O(p \times q)$
  • (c)$O(p^2 + q^2)$
  • (d)$O(p + q)$

Answer

Answer

Correct option: (d)

Answer: (d) $O(p + q)$ The two for-loops are independent (sequential, not nested): the first runs $p$ times giving $O(p)$, the second runs $q$ times giving $O(q)$. Adding two independent loop complexities gives worst-case complexity $O(p) + O(q) = O(p+q)$.