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 5 of 18

Explore more Topics under Data Structures and Algorithms

Q41.
Consider the following recursive implementation of the binary search. Which of the following lines should be added to complete the below code?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
       return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
      return mid;
      else if(arr[mid] < num)
          __________;
      else
          hi = mid - 1;
     return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[8] ={0,0,0,0,3,5,6,7},num = 7,len = 8;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}
Discuss
Answer: (d).lo = mid + 1
Q42.
What is the output of the following code?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
        return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
         return mid;
      else if(arr[mid] < num)
         lo = mid + 1;
      else
         hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[8] = {1,2,3,4,5,6,7,8},num = 7,len = 8;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}
Discuss
Answer: (c).Index of 7 is 6
Q43.
What is the output of the following code?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
       return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
       return mid;
      else if(arr[mid] < num)
          lo = mid + 1;
      else
          hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[8] = {0,0,0,0,3,5,6,7},num = 0,len = 8;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}
Discuss
Answer: (d).Index of 0 is 3
Q44.
In which of the below cases will the following code produce a wrong output?
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
       return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
       return mid;
      else if(arr[mid] < num)
          lo = mid + 1;
      else
          hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
Discuss
Answer: (c).Array: {5,4,3,2,1} Search: 1
Q45.
How many times is the function recursive_binary_search() called when the following code is executed?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
       return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
        return mid;
      else if(arr[mid] < num)
          lo = mid + 1;
      else
          hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[5] = {1,2,3,4,5},num = 1,len = 5;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}

a.

0

b.

1

c.

2

d.

3

Discuss
Answer: (c).2
Q46.
What is the output of the following code?
#include<stdio.h>
int recursive_binary_search(int *arr, int num, int lo, int hi)
{
      if(lo > hi)
        return -1;
      int mid = (lo + hi)/2;
      if(arr[mid] == num)
        return mid;
      else if(arr[mid] < num)
          lo = mid + 1;
      else
          hi = mid - 1;
      return recursive_binary_search(arr, num, lo, hi);
}
int main()
{
      int arr[5] = {5,4,3,2,1},num = 1,len = 5;
      int indx = recursive_binary_search(arr,num,0,len-1);
      printf("Index of %d is %d",num,indx);
      return 0;
}
Discuss
Answer: (c).Index of 1 is -1
Discuss
Answer: (c).Smaller instances of the same problem
Q48.
Which of the following problems can be solved using recursion?
Discuss
Answer: (d).All of the mentioned
Q49.
Recursion is similar to which of the following?
Discuss
Answer: (b).Loop
Q50.
In recursion, the condition for which the function will stop calling itself is ____________
Discuss
Answer: (c).Base case

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!