GATE | GATE 2017 MOCK II | Question 15
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
Last Updated :
28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...