0% found this document useful (0 votes)
69 views3 pages

MCQ 1 Recursion

The document contains multiple-choice questions (MCQs) focused on understanding recursion in programming. Topics include base cases, recursive execution, factorial and Fibonacci functions, tail recursion, infinite recursion, and memory usage in recursion. Each question provides four answer options related to the concepts of recursion.

Uploaded by

PEGASIS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views3 pages

MCQ 1 Recursion

The document contains multiple-choice questions (MCQs) focused on understanding recursion in programming. Topics include base cases, recursive execution, factorial and Fibonacci functions, tail recursion, infinite recursion, and memory usage in recursion. Each question provides four answer options related to the concepts of recursion.

Uploaded by

PEGASIS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MCQ 1: Understanding Recursion

What is the base case in a recursive function?

A) A case where the function calls itself


B) A case that stops recursion and prevents infinite loops
C) A case where the function executes in constant time
D) A case that always returns 0

MCQ 2: Identifying Recursive Execution

What will be the output of the following recursive method when mystery(5) is called?

public static void mystery(int n) {

if (n <= 0) {

return;

System.out.print(n + " ");

mystery(n - 1);

A) 5 4 3 2 1
B) 1 2 3 4 5
C) 5 4 3 2 1 0
D) 5 4 3 2 1

MCQ 3: Recursive Factorial Function

What is the return value of factorial(4) in the following recursive function?

public static int factorial(int n) {

if (n == 0) {

return 1;

return n * factorial(n - 1);

}
A) 4
B) 10
C) 24
D) 120

MCQ 4: Identifying Recursive Depth

How many times is the factorial method called when factorial(5) is executed?

A) 5
B) 6
C) 10
D) 15

MCQ 5: Recursive Fibonacci Function

How many times is fib(1) called when computing fib(5) using the following recursive method?

public static int fib(int n) {

if (n == 0) return 0;

if (n == 1) return 1;

return fib(n - 1) + fib(n - 2);

A) 3
B) 5
C) 8
D) 10

MCQ 6: Tail Recursion

Which of the following characteristics best describes tail recursion?

A) The recursive call is the last operation before returning the result
B) The recursive function is called multiple times before returning
C) The recursion stack grows indefinitely
D) It always executes faster than iteration
MCQ 7: Infinite Recursion

What happens if a recursive function lacks a base case?

A) The program executes successfully


B) The recursion stops automatically after 10 calls
C) The program enters an infinite recursion and eventually crashes (StackOverflowError)
D) The compiler detects and prevents the recursion

MCQ 8: Converting Recursion to Iteration

Which of the following recursive problems is easiest to convert into an iterative solution?

A) Tower of Hanoi
B) Fibonacci sequence
C) Factorial calculation
D) Merge Sort

MCQ 9: Memory Usage in Recursion

What is the main disadvantage of using recursion instead of iteration?

A) It always takes more time to execute


B) It uses more memory due to function call stack overhead
C) It cannot be used in Java
D) It is difficult to implement

MCQ 10: Recursion and Base Case Errors

What happens if we mistakenly define if (n == 1) return 0; instead of if (n == 0) return 1; in a factorial


function?

A) The function returns the correct factorial value


B) The function returns 0 for all values
C) The function causes a StackOverflowError
D) The function behaves normally for n > 1

You might also like