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

Q131.
What is the output of the following code?
#include<stdio.h>
int get_len(char *s)
{
      int len = 0;
      while(s[len] != '\0')
        len++;
      return len;
}
int main()
{
      char *s = "";
      int len = get_len(s);
      printf("%d",len);
      return 0;
}
Discuss
Answer: (a).0
Q132.
Which of the following can be the base case for the recursive implementation used to find the length of a string?
Discuss
Answer: (c).if(string[len] == ‘\0’) return 0
Q133.
Consider the following recursive implementation used to find the length of a string:
Which of the following lines should be inserted to complete thebelow code?
#include<stdio.h>
int recursive_get_len(char *s, int len)
{
      if(s[len] == 0)
        return 0;
      return ________;
}
int main()
{
      char *s = "abcdef";
      int len = recursive_get_len(s,0);
      printf("%d",len);
      return 0;
}

Discuss
Answer: (d).1 + recursive_get_len(s, len+1)
Q134.
What is the output of the following code?
#include<stdio.h>
int recursive_get_len(char *s, int len)
{
      if(s[len] == 0)
        return 0;
      return 1 + recursive_get_len(s, len+1);
}
int main()
{
      char *s = "abcdef";
      int len = recursive_get_len(s,0);
      printf("%d",len);
      return 0;
}

a.

5

b.

6

c.

7

d.

8

Discuss
Answer: (b).6
Q135.
What is the time complexity of the above recursive implementation used to find the length of the string?
Discuss
Answer: (b).O(n)
Q136.
How many times is the function recursive_get_len() called when the following code is executed?
#include<stdio.h>
int recursive_get_len(char *s, int len)
{
      if(s[len] == 0)
        return 0;
      return 1 + recursive_get_len(s, len+1);
}
int main()
{
      char *s = "adghjkl";
      int len = recursive_get_len(s,0);
      printf("%d",len);
      return 0;
}

a.

6

b.

7

c.

8

d.

9

Discuss
Answer: (c).8
Q137.
What is the output of the following code?
#include<stdio.h>
int recursive_get_len(char *s, int len)
{
      if(s[len] == 0)
        return 0;
      return 1 + recursive_get_len(s, len+1);
}
int main()
{
      char *s = "123-1-2-3";
      int len = recursive_get_len(s,0);
      printf("%d",len);
      return 0;
}

a.

3

b.

6

c.

9

d.

10

Discuss
Answer: (c).9
Q138.
Which of the following methods can be used to find the largest and smallest element in an array?
Discuss
Answer: (c).Both recursion and iteration
Q139.
Consider the following iterative code snippet to find the largest element:
Which of the following lines should be inserted to complete the below code?
int get_max_element(int *arr,int n)
{
      int i, max_element = arr[0];
      for(i = 1; i < n; i++)
          if(________)
          max_element = arr[i];
      return max_element;
}
Discuss
Answer: (a).arr[i] > max_element
Q140.
Consider the following code snippet to find the smallest element in an array:
Which of the following lines should be inserted to complete the below code?
int get_min_element(int *arr, int n)
{
      int i, min_element = arr[0];
      for(i = 1; i < n; i++)
        if(_______)
          min_element = arr[i];
      return min_element;
}
Discuss
Answer: (b).arr[i] < min_element

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!