GATE Exam  >  GATE Questions  >  Consider the C code Below.void function(int n... Start Learning for Free
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)
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Consider the C code Below.void function(int n){ if (n == 1) return;...
Important observation is Break statement terminates the innermost loop. So “*” is printed only n times.
View all questions of this test
Most Upvoted Answer
Consider the C code Below.void function(int n){ if (n == 1) return;...
The code seems to be incomplete as it ends abruptly with a for-loop without any closing braces. However, based on the available code, it appears to be a recursive function that takes an integer parameter 'n' and performs some operation on it.

The if-statement checks if the value of 'n' is equal to 1, and if so, it immediately returns from the function. This is the base case for the recursion.

If the value of 'n' is not 1, then the function enters a for-loop that initializes an integer variable 'i' to 0 and continues the loop as long as 'i' is less than 'n'. The loop performs some operation on 'i', but since the code is incomplete, we cannot determine what that operation is.

After the for-loop, the function calls itself with the parameter value of 'n-1'. This is where the recursion takes place, as the function keeps calling itself with decreasing values of 'n' until it reaches the base case where 'n' is equal to 1.

Overall, the purpose of the function and the operation it performs are unclear without more context or complete code.
Explore Courses for GATE exam
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)Correct answer is option 'B'. Can you explain this answer?
Question Description
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)Correct answer is option 'B'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about 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)Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for 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)Correct answer is option 'B'. Can you explain this answer?.
Solutions for 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)Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of 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)Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of 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)Correct answer is option 'B'. Can you explain this answer?, a detailed solution for 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)Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of 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)Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice 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)Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev