PRASHNIKAप्रश्निका

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

Computer Science20261 markMCQ
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

AI
Written by AI (antigravity) - it can contain mistakes.

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²).
Complexity and Big O notation

From ISC 2026 Computer Science Paper 1, question 1(v).

See every question