adplus-dvertising

Welcome to the Recursion MCQs Page

Dive deep into the fascinating world of Recursion with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Recursion, a crucial aspect of Data Structures and Algorithms. In this section, you will encounter a diverse range of MCQs that cover various aspects of Recursion, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Data Structures and Algorithms.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Recursion. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Data Structures and Algorithms.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Recursion. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Recursion MCQs | Page 9 of 18

Q81.
What is the output of the following code?
int fibo(int n)
{
      if(n == 1)
        return 0;
      else if(n == 2)
        return 1;
      return fibo(n - 1) + fibo(n - 2);
}
int main()
{
     int n = -1;
     int ans = fibo(n);
     printf("%d",ans);
     return 0;
}
Discuss
Answer: (d).Runtime error
Q82.
What is the output of the following code?
int fibo(int n)
{
      if(n == 1)
        return 0;
      else if(n == 2)
        return 1;
      return fibo(n - 1) + fibo(n - 2);
}
int main()
{
     int n = 5;
     int ans = fibo(n);
     printf("%d",ans);
     return 0;
}

a.

1

b.

2

c.

3

d.

5

Discuss
Answer: (c).3
Q83.
How many times will the function fibo() be called when the following code is executed?
int fibo(int n)
{
      if(n == 1)
         return 0;
      else if(n == 2)
        return 1;
      return fibo(n - 1) + fibo(n - 2);
}
int main()
{
     int n = 5;
     int ans = fibo(n);
     printf("%d",ans);
     return 0;
}

a.

5

b.

6

c.

8

d.

9

Discuss
Answer: (d).9
Q84.
What is the output of the following code?
int fibo(int n)
{ 
      if(n == 1)
        return 0;
      else if(n == 2)
        return 1;
      return fibo(n - 1) + fibo(n - 2);
}
int main()
{
     int n = 10;
     int ans = fibo(n);
     printf("%d",ans);
     return 0;
}
Discuss
Answer: (b).34
Q85.
Which of the following methods can be used to find the sum of first n natural numbers?
Discuss
Answer: (d).All of the mentioned
Q86.
Which of the following gives the sum of the first n natural numbers?
Discuss
Answer: (c).(n+1)C2
Q87.
Consider the following iterative solution to find the sum of first n natural numbers:
Which of the following lines completes thebelow code?
#include<stdio.h>
int get_sum(int n)
{
      int sm = 0, i;
      for(i = 1; i <= n; i++)
        ________;
      return sm;
}
int main()
{
    int n = 10;
    int ans = get_sum(n);
    printf("%d",ans);
    return 0;
}

Discuss
Answer: (b).sm += i
Q88.
What is the output of the following code?
#include<stdio.h>
int get_sum(int n)
{
      int sm, i;
      for(i = 1; i <= n; i++)
        sm += i;
      return sm;
}
int main()
{
    int n = 10;
    int ans = get_sum(n);
    printf("%d",ans);
    return 0;
}
Discuss
Answer: (d).none of the mentioned
Q89.
What is the time complexity of the above iterative method used to find the sum of the first n natural numbers?
Discuss
Answer: (b).O(n)
Q90.
Consider the following code:
Which of the following lines is the recurrence relation for thebelow code?
#include<stdio.h>
int recursive_sum(int n)
{
      if(n == 0)
        return 0;
      return ________;
}
int main()
{
    int n = 5;
    int ans = recursive_sum(n);
    printf("%d",ans);
    return 0;
}

Discuss
Answer: (c).n + recursive_sum(n – 1)

Suggested Topics

Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!