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

Q141.
What is the output of the following code?
#include<stdio.h>
int get_max_element(int *arr,int n)
{
      int i, max_element = arr[0];
      for(i = 1; i < n; i++)
        if(arr[i] > max_element)
          max_element = arr[i];
      return max_element;
}
int get_min_element(int *arr, int n)
{
      int i, min_element = arr[0];
      for(i = 1; i < n; i++)
        if(arr[i] < min_element)
          min_element = arr[i];
      return min_element;
}
int main()
{
     int n = 7, arr[7] = {5,2,4,7,8,1,3};
     int max_element = get_max_element(arr,n);
     int min_element = get_min_element(arr,n);
     printf("%d %d",max_element,min_element);
     return 0;
}
Discuss
Answer: (c).8 1
Q142.
What is the output of the following code?
#include<stdio.h>
int get_max_element(int *arr,int n)
{
      int i, max_element = arr[0];
      for(i = 1; i < n; i++)
        if(arr[i] > max_element)
          max_element = arr[i];
      return max_element;
}
int get_min_element(int *arr, int n)
{
      int i, min_element;
      for(i = 1; i < n; i++)
        if(arr[i] < min_element)
          min_element = arr[i];
      return min_element;
}
int main()
{
     int n = 7, arr[7] = {1,1,1,0,-1,-1,-1};
     int max_element = get_max_element(arr,n);
     int min_element = get_min_element(arr,n);
     printf("%d %d",max_element,min_element);
     return 0;
}
Discuss
Answer: (c).1 Garbage value
Q143.
What is the time complexity of the above iterative implementation used to find the largest and smallest element in an array?
Discuss
Answer: (b).O(n)
Q144.
Consider the following recursive implementation to find the largest element in an array:
Which of the following lines should be inserted to complete the below code?
int max_of_two(int a, int b)
{
      if(a > b)
        return a;
      return b;
}
int recursive_max_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return _______;
}
Discuss
Answer: (c).max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1))
Q145.
What is the output of the following code?
#include<stdio.h>
int max_of_two(int a, int b)
{
      if(a > b)
        return a;
      return b;
}
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_max_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1));
}
int recursive_min_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
    int n = 10, idx = 0, arr[] = {5,2,6,7,8,9,3,-1,1,10};
    int max_element = recursive_max_element(arr,n,idx);
    int min_element = recursive_min_element(arr,n,idx);
    printf("%d %d",max_element,min_element);
    return 0;
}
Discuss
Answer: (b).10 -1
Q146.
What is the time complexity of the above recursive implementation used to find the largest and the smallest element in an array?
Discuss
Answer: (b).O(n)
Q147.
How many times is the function recursive_min_element() called when the following code is executed?
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_min_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
     int n = 10, idx = 0, arr[] = {5,2,6,7,8,9,3,-1,1,10};
     int min_element = recursive_min_element(arr,n,idx);
     printf("%d",min_element);
     return 0;
}
Discuss
Answer: (b).10
Q148.
What is the output of the following code?
#include<stdio.h>
int max_of_two(int a, int b)
{
      if(a > b)
        return a;
      return b;
}
int min_of_two(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int recursive_max_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1));
}
int recursive_min_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return min_of_two(arr[idx], recursive_min_element(arr, len, idx + 1));
}
int main()
{
     int n = 5, idx = 0, arr[] = {1,1,1,1,1};
     int max_element = recursive_max_element(arr,n,idx);
     int min_element = recursive_min_element(arr,n,idx);
     printf("%d %d",max_element,min_element);
     return 0;
}
Discuss
Answer: (a).1 1
Q149.
Which of the following methods can be used to find the largest and smallest number in a linked list?
Discuss
Answer: (c).Both Recursion and iteration
Q150.
Consider the following code snippet to find the largest 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 get_max()
{
      struct Node* temp = head->next;
   int max_num = temp->val;
   while(______)
   {
         if(temp->val > max_num)
      max_num = temp->val;
  temp = temp->next;
   }
   return max_num;
}
Discuss
Answer: (b).temp != 0

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!