Skip to content
Related Articles

Related Articles

GATE | GATE 2017 MOCK II | Question 15

View Discussion
Improve Article
Save Article
  • Last Updated : 28 Jun, 2021

Consider the C code Below.

void function(int n)
{
    if (n == 1) 
      return;
    for (int i = 0; i<n; i++)
    {
        for (int j = 1; j< = n; j++)
        {
            printf("*");            
            break;
        }
    }
}

Which of the following is the tightest upper bound on time complexity of above function.

(A) O(n2)
(B) O(n)
(C) O(n log n)
(D) O(1)


Answer: (B)

Explanation: Important observation is Break statement terminates the innermost loop.
So “*” is printed only n times.


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!