Software Development Exam  >  Software Development Tests  >  Test: Recursion - 2 - Software Development MCQ

Test: Recursion - 2 - Software Development MCQ


Test Description

15 Questions MCQ Test - Test: Recursion - 2

Test: Recursion - 2 for Software Development 2024 is part of Software Development preparation. The Test: Recursion - 2 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Recursion - 2 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Recursion - 2 below.
Solutions of Test: Recursion - 2 questions in English are available as part of our course for Software Development & Test: Recursion - 2 solutions in Hindi for Software Development course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Recursion - 2 | 15 questions in 30 minutes | Mock test for Software Development preparation | Free important questions MCQ to study for Software Development Exam | Download free PDF with solutions
Test: Recursion - 2 - Question 1

What is recursion in programming?

Detailed Solution for Test: Recursion - 2 - Question 1

Recursion is a problem-solving technique where a function calls itself to solve a smaller instance of the same problem.

Test: Recursion - 2 - Question 2

What is the base case in a recursive function?

Detailed Solution for Test: Recursion - 2 - Question 2

The base case in a recursive function is the condition that stops the recursion and allows the function to start returning values.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Recursion - 2 - Question 3

What is the purpose of a recursive function?

Detailed Solution for Test: Recursion - 2 - Question 3

Recursion is often used to solve problems that can be broken down into smaller, simpler instances of the same problem.

Test: Recursion - 2 - Question 4

Which of the following is true about recursion?

Detailed Solution for Test: Recursion - 2 - Question 4

Recursion can use more memory than iteration because each recursive call adds a new stack frame to the call stack.

Test: Recursion - 2 - Question 5

What happens if a recursive function does not have a base case?

Detailed Solution for Test: Recursion - 2 - Question 5

Without a base case, the recursive function will continue to call itself indefinitely, leading to an infinite loop.

Test: Recursion - 2 - Question 6

What is the output of the following code?

#include <iostream>

void printNumbers(int n) {
    if (n <= 0)
        return;

    std::cout << n << " ";
    printNumbers(n - 1);
}

int main() {
    printNumbers(5);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 6

The printNumbers function prints the number n and then calls itself with n-1 until n becomes less than or equal to 0.

Test: Recursion - 2 - Question 7

What is the output of the following code?
#include <iostream>

int sum(int n) {
    if (n == 0)
        return 0;
    
    return n + sum(n - 1);
}

int main() {
    std::cout << sum(4);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 7

The sum function calculates the sum of numbers from n to 1 by recursively adding n with sum(n - 1).

Test: Recursion - 2 - Question 8

What is the output of the following code?
#include <iostream>

int factorial(int n) {
    if (n == 0 || n == 1)
        return 1;
    
    return n * factorial(n - 1);
}

int main() {
    std::cout << factorial(5);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 8

The factorial function calculates the factorial of a number n by recursively multiplying n with factorial(n - 1).

Test: Recursion - 2 - Question 9

What is the output of the following code?
#include <iostream>

void printPattern(int n) {
    if (n <= 0)
        return;
    
    std::cout << n << " ";
    printPattern(n - 2);
    std::cout << n << " ";
}

int main() {
    printPattern(5);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 9

The printPattern function prints the number n, calls itself with n-2, and then prints n again after the recursive call.

Test: Recursion - 2 - Question 10

What is the output of the following code?
#include <iostream>

int fibonacci(int n) {
    if (n <= 1)
        return n;
    
    return fibonacci(n - 1) + fibonacci(n - 2);
}

int main() {
    std::cout << fibonacci(6);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 10

The fibonacci function calculates the nth Fibonacci number using recursion. In this case, fibonacci(6) returns 8.

Test: Recursion - 2 - Question 11

What does the following code do?
#include <iostream>

int countDigits(int n) {
    if (n < 10)
        return 1;
    
    return 1 + countDigits(n / 10);
}

int main() {
    std::cout << countDigits(12345);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 11

The countDigits function uses recursion to count the number of digits in a positive integer n.

Test: Recursion - 2 - Question 12

What does the following code do?
#include <iostream>

int power(int base, int exponent) {
    if (exponent == 0)
        return 1;
    
    return base * power(base, exponent - 1);
}

int main() {
    std::cout << power(2, 3);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 12

The power function calculates the power of a number base to the exponent using recursion.

Test: Recursion - 2 - Question 13

What does the following code do?
#include <iostream>

int gcd(int a, int b) {
    if (b == 0)
        return a;
    
    return gcd(b, a % b);
}

int main() {
    std::cout << gcd(18, 24);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 13

The gcd function uses recursion to compute the greatest common divisor (GCD) of two numbers a and b.

Test: Recursion - 2 - Question 14

What does the following code do?
#include <iostream>

bool isPalindrome(const std::string& str, int start, int end) {
    if (start >= end)
        return true;
    
    return (str[start] == str[end]) && isPalindrome(str, start + 1, end - 1);
}

int main() {
    std::cout << isPalindrome("racecar", 0, 6);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 14

The isPalindrome function checks if a string is a palindrome by comparing characters from both ends using recursion.

Test: Recursion - 2 - Question 15

What does the following code do?
#include <iostream>

void printBinary(int n) {
    if (n == 0)
        return;
    
    printBinary(n / 2);
    std::cout << n % 2;
}

int main() {
    printBinary(10);
    return 0;
}

Detailed Solution for Test: Recursion - 2 - Question 15

The printBinary function prints the binary representation of a number n by recursively dividing n by 2 and printing the remainder.

Information about Test: Recursion - 2 Page
In this test you can find the Exam questions for Test: Recursion - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Recursion - 2, EduRev gives you an ample number of Online tests for practice

Top Courses for Software Development

Download as PDF

Top Courses for Software Development