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

Explore more Topics under Data Structures and Algorithms

Q161.
Consider the array {1,1,1,1,1}:
Which of the following techniques can be used to search an element in the above array?
Discuss
Answer: (d).All of the mentioned
Q162.
What does the following code do?
#include<stdio.h>
int search_num(int *arr, int num, int len)
{
     int i;
     for(i = 0; i < len; i++)
     if(arr[i] == num)
      return i;
     return -1;
}
int main()
{
      int arr[5] ={1,2,3,4,5},num=3,len = 5;
      int indx = search_num(arr,num,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}
Discuss
Answer: (b).Finds the index of the first occurrence of the number that is searched
Q163.
What is the output of the following code?
#include<stdio.h>
int search_num(int *arr, int num, int len)
{
     int i;
     for(i = 0; i < len; i++)
     if(arr[i] == num)
        return i;
     return -1;
}
int main()
{
      int arr[5] ={1,3,3,3,5},num=3,len = 5;
      int indx = search_num(arr,num,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}
Discuss
Answer: (b).Index of 3 is 1
Q164.
Consider the following recursive implementation of linear search:
Which of the following recursive calls should be added to complete the below code?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
     return -1;
     if(arr[idx] == num)
       return idx;
     return __________;
}
int main()
{
      int arr[5] ={1,3,3,3,5},num=2,len = 5;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

Discuss
Answer: (c).recursive_search_num(arr, num, idx+1, len);
Q165.
What is the output of the following code?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
     return -1;
     if(arr[idx] == num)
       return idx;
     return recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={1,2,3,3,3,5,6,7},num=5,len = 8;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}
Discuss
Answer: (a).Index of 5 is 5
Q166.
How many times is the function recursive_search_num() called when the following code is executed?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
     return -1;
     if(arr[idx] == num)
     return idx;
     return recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={1,2,3,3,3,5,6,7},num=5,len = 8;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

a.

5

b.

6

c.

7

d.

8

Discuss
Answer: (b).6
Q167.
What is the time complexity of the above recursive implementation of linear search?
Discuss
Answer: (b).O(n)
Q168.
What is the output of the following code?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
      return -1;
     if(arr[idx] == num)
      return idx;
     return recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={-11,2,-3,0,3,5,-6,7},num = -2,len = 8;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}
Discuss
Answer: (c).Index of -2 is -1
Q169.
Which of the following methods can be used to search an element in a linked list?
Discuss
Answer: (a).Iterative linear search
Q170.
Consider the following code snippet to search an element in a linked list:
Which of the following lines should be inserted to complete the below code?
struct Node
{
     int val;
     struct Node* next;
}*head;
int linear_search(int value)
{
      struct Node *temp = head->next;
      while(temp != 0)
      {
           if(temp->val == value)
              return 1;
           _________;
      }
      return 0;
}
Discuss
Answer: (c).temp = temp->next

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!