• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Recursion Algorithm with Answers

Question 21

The solution of the recurrence relation T(m) = T(3m / 4) + 1 is :
  • θ (lg m)
  • θ (m)
  • θ (mlg m)
  • θ (lglg m)

Question 22

The function f is defined as follows: 

C
int f (int n) {
    if (n <= 1) return 1;
    else if (n % 2  ==  0) return f(n/2);
    else return f(3n - 1);
}

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
1. The function f terminates for finitely many different values of n ≥ 1. 
ii. The function f terminates for infinitely many different values of n ≥ 1. 
iii. The function f does not terminate for finitely many different values of n ≥ 1. 
iv. The function f does not terminate for infinitely many different values of n ≥ 1. 
Which one of the following options is true of the above?

  • (i) and (iii)

  • (i) and (iv)

  • (ii) and (iii)

  • (ii) and (iv)

Question 23

Consider the code fragment written in JAVA below : 

Java
void f (int n)
{ 
  if (n <=1)  {
   System.out.print(n);
  }
  else {
   f (n/2);
   System.out.print(n%2);
  }
}

What does f(173) print?

  • 010110101

  • 010101101

  • 10110101

  • 10101101

Question 24

What is the output of the following program? 

C++
#include <stdio.h>

void print(int n, int j)
{
    if (j >= n)
        return;
    if (n - j > 0 && n - j >= j)
       printf("%d %d\n", j, n-j);
   print(n, j+1);
}

int main()
{
    int n = 8;
    print(n, 1);
}
  • 1 7
    2 6
    3 5
    4 4
    4 4

  • 1 7
    2 6
    3 5
    4 4

  • 1 7
    2 6
    3 5
     

  • 1 2
    3 4
    5 6
    7 8

Question 25

What is the name of below recursive program?

C++
void fun(int n, char from_rod, char to_rod,
				char aux_rod)
{
	if (n == 0) {
		return;
	}
	fun(n - 1, from_rod, aux_rod, to_rod);
	cout << "Move disk " << n << " from rod " << from_rod
		<< " to rod " << to_rod << endl;
	fun(n - 1, aux_rod, to_rod, from_rod);
}
  • N Queen Problem

  • Tower of Hanoi

  • M coloring Problem

  • None

Question 26

What is the output of the below program for the tree:

[caption width="800"]Tree[/caption] C++
void printInorder(struct Node* node)
{
    if (node == NULL)
        return;

    printInorder(node->left);
    cout << node->data << " ";
    printInorder(node->right);
}
  • 1 2 3 4 5 

  • 1 3 4 5 2

  • 4 2 5 1 3

  • 5 4 3 2 1

Question 27

What is the output of the following code for the input arr[]={1,2,3,4,5,6} N=6?

C++
int fun(int A[], int N)
{
	if (N <= 0)
		return 0;
	return (fun(A, N - 1) + A[N - 1]);
}
  • 21

  • 0

  • Runtime error

  • None

Question 28

Consider the below Program and identify the problem:

C++
void fun2(int arr[], int start_index, int end_index)
{
    if (start_index >= end_index)
        return;
    int min_index;
    int temp;
    min_index = minIndex(arr, start_index, end_index);
    swap(arr[start_index], arr[min_index]);
    fun2(arr, start_index + 1, end_index);
}
  • Selection Sort Recursive implementation

  • Bubble sort Recursive implementation

  • Finding Pair Recursive implementation

  • None of these

Question 29

Match the pairs in the following questions: 

List 1List 2
A. Recursion1. Sorted Array
B. Binary Seach2. Recursion
C. Sorting3 Base case
D. Dynamic Programming4.O(NlogN)
  • A – 2, B – 1, C – 4, D – 3

  • A – 3, B – 4, C – 1, D – 2

  • A – 3, B – 1, C – 4, D – 2

  • A – 2, B – 4, C – 1, D – 3

Question 30

Consider the below program, what operation is performed below:

C++
void fun(int arr[], int n)
{
	
	if (n == 1)
		return;

	int count = 0;
	for (int i=0; i<n-1; i++)
		if (arr[i] > arr[i+1]){
			swap(arr[i], arr[i+1]);
			count++;
		}
		return;
	fun(arr, n-1);
}
  • Insertion Sort Recursively

  • Bubble Sort Recursively

  • Selection Sort Recursively

  • None

There are 30 questions to complete.

Last Updated :
Take a part in the ongoing discussion

Trending in News

View More