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

Explore more Topics under Data Structures and Algorithms

Q31.
A recursive agorithm must have
Discuss
Answer: (b).2 parts
Q32.
If an algorithm calls itself to do some part of work, it is said to be
Discuss
Answer: (b).Recursive
Q33.
What is the output of the following code?
#include<stdio.h>
#include<string.h>
void reverse_string(char *s)
{
     int len = strlen(s);
     int i,j;
     i=0;
     j=len-1;
     while(i < j)
     {
         char tmp = s[i];
         s[i] = s[j];
         s[j] = tmp;
         i++;
         j--;
     }
}
int main()
{
      char s[100] = "reverse";
      reverse_string(s);
      printf("%s",s);
      return 0;
}
Discuss
Answer: (b).esrever
Q34.
What does the following code do?
#include<stdio.h>
#include<string.h>
void reverse_string(char *s)
{
     int len = strlen(s);
     int i,j;
     i=0;
     j=len-1;
     while(i < j)
     {
         char tmp = s[i];
         s[i] = s[j];
         s[j] = tmp;
         i++;
         j--;
     }
}
int main()
{
      char s[100] = "abcdefg";
      char t[100];
      strcpy(t,s);
      reverse_string(s);
      if(strcmp(t,s) == 0)
        printf("Yes");
      else
        printf("No");
      return 0;
}
Discuss
Answer: (d).Checks if a string is a palindrome
Q35.
What is the output of the following code?
#include<stdio.h>
#include<string.h>
void reverse_string(char *s)
{
     int len = strlen(s);
     int i,j;
     i=0;
     j=len-1;
     while(i < j)
     {
         char tmp = s[i];
         s[i] = s[j];
         s[j] = tmp;
         i++;
         j--;
     }
}
int main()
{
      char s[100] = "rotator";
      char t[100];
      strcpy(t,s);
      reverse_string(s);
      if(strcmp(t,s) == 0)
        printf("Yes");
      else
        printf("No");
      return 0;
}
Discuss
Answer: (a).Yes
Q36.
Consider the following recursive implementation used to reverse a string:.
Which of the following lines should be inserted to complete the below code?
void recursive_reverse_string(char *s, int left, int right)
{
     if(left < right)
     {
         char tmp = s[left];
         s[left] = s[right];
         s[right] = tmp;
         _________;
     }
}
Discuss
Answer: (d).recursive_reverse_string(s, left-1, right+1)
Q37.
What is the output of the following code?
#include<stdio.h>
#include<string.h>
void recursive_reverse_string(char *s, int left, int right)
{
     if(left < right)
     {
         char tmp = s[left];
         s[left] = s[right];
         s[right] = tmp;
         recursive_reverse_string(s, left+1, right-1);
     }
}
int main()
{
     char s[100] = "recursion";
     int len = strlen(s);
     recursive_reverse_string(s,0,len-1);
     printf("%s",s);
     return 0;
}
Discuss
Answer: (d).noisrucer
Q38.
How many times is the function recursive_reverse_string() called when the following code is executed?
#include<stdio.h>
#include<string.h>
void recursive_reverse_string(char *s, int left, int right)
{
     if(left < right)
     {
         char tmp = s[left];
         s[left] = s[right];
         s[right] = tmp;
         recursive_reverse_string(s, left+1, right-1);
     }
}
int main()
{
     char s[100] = "madam";
     int len = strlen(s);
     recursive_reverse_string(s,0,len-1);
     printf("%s",s);
     return 0;
}

a.

3

b.

4

c.

5

d.

6

Discuss
Answer: (a).3
Q39.
For which of the following cases will the reversal of a string be equal to the original string?
Discuss
Answer: (d).All of the mentioned
Q40.
What does the following code do?
#include<stdio.h>
int cnt = 0;
int recursive_search_num(int *arr, int num, int idx, int len)
{
      int cnt = 0;
      if(idx == len)
      return cnt;
      if(arr[idx] == num)
       cnt++;
      return cnt + recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={0,0,0,0,3,5,-6,7},num = 0,len = 8;
      int ans = recursive_search_num(arr,num,0,len);
      printf("%d",ans);
      return 0;
}
Discuss
Answer: (c).Counts the number of occurrences of the number 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!