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
Recommended Posts:
- GATE | GATE MOCK 2017 | Question 27
- GATE | GATE MOCK 2017 | Question 43
- GATE | GATE MOCK 2017 | Question 44
- GATE | GATE MOCK 2017 | Question 45
- GATE | GATE MOCK 2017 | Question 46
- GATE | GATE MOCK 2017 | Question 47
- GATE | GATE MOCK 2017 | Question 48
- GATE | GATE MOCK 2017 | Question 49
- GATE | GATE MOCK 2017 | Question 50
- GATE | GATE MOCK 2017 | Question 51
- GATE | GATE MOCK 2017 | Question 52
- GATE | GATE MOCK 2017 | Question 53
- GATE | GATE MOCK 2017 | Question 42
- GATE | GATE MOCK 2017 | Question 41
- GATE | GATE MOCK 2017 | Question 40



