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

Question 1(v)

1 mark

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

Choose the correct option.

The worst case complexity for following code segment is: for(int i=1; i<= n; i++) { for(int j=1…

The worst case complexity for following code segment is:
for(int i=1; i<= n; i++)
{
    for(int j=1; j<= i; j++)
    {
        statement;
    }
}
  • (a)O(n+i)
  • (b)O(n×i)
  • (c)O(n)
  • (d)O(n²)

Answer

Answer

Correct option: (d)

Answer: (d) O(n²) The outer loop executes n times and for each i, the inner loop executes i times. Total executions = 1 + 2 + ... + n = n(n + 1)/2, which gives worst case complexity O(n²).