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.
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 16 of 18
Explore more Topics under Data Structures and Algorithms
Which of the following lines should be inserted to complete the below code?
struct Node
{
int val;
struct Node* next;
}*head;
int get_min()
{
struct Node* temp = head->next;
int min_num = temp->val;
while(temp != 0)
{
if(_________)
min_num = temp->val;
temp = temp->next;
}
return min_num;
}
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int val;
struct Node* next;
}*head;
int get_max()
{
struct Node* temp = head->next;
int max_num = temp->val;
while(temp != 0)
{
if(temp->val > max_num)
max_num = temp->val;
temp = head->next;
}
return max_num;
}
int main()
{
int n = 9, arr[9] ={5,1,3,4,5,2,3,3,1},i;
struct Node *temp, *newNode;
head = (struct Node*)malloc(sizeof(struct Node));
head -> next =0;
temp = head;
for(i=0;i<n;i++)
{
newNode =(struct Node*)malloc(sizeof(struct Node));
newNode->next = 0;
newNode->val = arr[i];
temp->next =newNode;
temp = temp->next;
}
int max_num = get_max();
printf("%d %d",max_num);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int val;
struct Node* next;
}*head;
int get_max()
{
struct Node* temp = head->next;
int max_num = temp->val;
while(temp != 0)
{
if(temp->val > max_num)
max_num = temp->val;
temp = temp->next;
}
return max_num;
}
int get_min()
{
struct Node* temp = head->next;
int min_num = temp->val;
while(temp != 0)
{
if(temp->val < min_num)
min_num = temp->val;
temp = temp->next;
}
return min_num;
}
int main()
{
int i, n = 9, arr[9] ={8,3,3,4,5,2,5,6,7};
struct Node *temp, *newNode;
head = (struct Node*)malloc(sizeof(struct Node));
head -> next =0;
temp = head;
for(i=0;i<n;i++)
{
newNode =(struct Node*)malloc(sizeof(struct Node));
newNode->next = 0;
newNode->val = arr[i];
temp->next =newNode;
temp = temp->next;
}
int max_num = get_max();
int min_num = get_min();
printf("%d %d",max_num,min_num);
return 0;
}
Which of the following arguments should be passed to the function max_of two() to complete the below code?
struct Node
{
int val;
struct Node* next;
}*head;
int max_of_two(int a, int b)
{
if(a > b)
return a;
return b;
}
int recursive_get_max(struct Node* temp)
{
if(temp->next == 0)
return temp->val;
return max_of_two(______, _______);
}
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int val;
struct Node* next;
}*head;
int max_of_two(int a, int b)
{
if(a > b)
return a;
return b;
}
int recursive_get_max(struct Node* temp)
{
if(temp->next == 0)
return temp->val;
return max_of_two(temp->val,recursive_get_max(temp->next));
}
int min_of_two(int a, int b)
{
if(a < b)
return a;
return b;
}
int recursive_get_min(struct Node* temp)
{
if(temp->next == 0)
return temp->val;
return min_of_two(temp->val,recursive_get_min(temp->next));
}
int main()
{
int n = 9, arr[9] ={1,3,2,4,5,0,5,6,7},i;
struct Node *temp, *newNode;
head = (struct Node*)malloc(sizeof(struct Node));
head -> next =0;
temp = head;
for(i=0;i<n;i++)
{
newNode =(struct Node*)malloc(sizeof(struct Node));
newNode->next = 0;
newNode->val = arr[i];
temp->next =newNode;
temp = temp->next;
}
int max_num = recursive_get_max(head->next);
int min_num = recursive_get_min(head->next);
printf("%d %d",max_num,min_num);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int val;
struct Node* next;
}*head;
int min_of_two(int a, int b)
{
if(a < b)
return a;
return b;
}
int recursive_get_min(struct Node* temp)
{
if(temp->next == 0)
return temp->val;
return min_of_two(temp->val,recursive_get_min(temp->next));
}
int main()
{
int n = 5, arr[5] ={1,1,1,1,1},i;
struct Node *temp, *newNode;
head = (struct Node*)malloc(sizeof(struct Node));
head -> next =0;
temp = head;
for(i=0;i<n;i++)
{
newNode =(struct Node*)malloc(sizeof(struct Node));
newNode->next = 0;
newNode->val = arr[i];
temp->next =newNode;
temp = temp->next;
}
int min_num = recursive_get_min(head->next);
printf("%d",min_num);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int val;
struct Node* next;
}*head;
int min_of_two(int a, int b)
{
if(a < b)
return a;
return b;
}
int recursive_get_min(struct Node* temp)
{
if(temp->next == 0)
return temp->val;
return min_of_two(temp->val,recursive_get_min(temp->next));
}
int main()
{
int n = 5, arr[5] ={1,1,1,1,1},i;
struct Node *temp, *newNode;
head = (struct Node*)malloc(sizeof(struct Node));
head -> next =0;
temp = head;
for(i=0;i<n;i++)
{
newNode =(struct Node*)malloc(sizeof(struct Node));
newNode->next = 0;
newNode->val = arr[i];
temp->next =newNode;
temp = temp->next;
}
int min_num = recursive_get_min(head->next);
printf("%d",min_num);
return 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!