What is the base case in recursion?
A) A recursive call to a smaller problem
B) A condition that stops the recursion
C) A case that calls itself indefinitely
D) A loop that repeats a process
B) A condition that stops the recursion
What happens if a recursive method does not have a base case?
A) It runs indefinitely, leading to a stack overflow error
B) It stops immediately
C) It converts into an iterative loop
D) It prints the base case and exits
A) It runs indefinitely, leading to a stack overflow error
Which of the following problems is BEST suited for recursion?
A) Printing numbers from 1 to 100
B) Finding the largest element in an array
C) Computing the Fibonacci sequence
D) Sorting an array using selection sort
C) Computing the Fibonacci sequence
How can recursion be less efficient than iteration?
Recursive calls use additional memory on the call stack, which can lead to slower performance and stack overflow.
This sorting algorithm builds a sorted portion of the array by repeatedly taking the next element and placing it in the correct position within the sorted part.
a. Merge sort
b. Insertion sort
c. Binary sort
d. Stalin sort
b. Insertion Sort
This part of a recursive method defines how the problem is broken down and calls itself with a smaller subproblem.
a. Recursive case
b. Base case
c. Iteration case
d. Operator case
a. Recursive case
output of : mystery(5)
public static void mystery(int n) {
if (n > 0) {
System.out.print(n + " ");
mystery(n - 2); }}
5 3 1
What is the key difference between direct and indirect recursion?
Direct recursion occurs when a method calls itself, while indirect recursion happens when multiple methods call each other in a cycle.
This sorting algorithm uses recursion to divide an array into smaller parts before merging them back together.
Merge sort
This searching algorithm requires a sorted array and repeatedly divides the search space in half to locate the target value.
a. Adithiya search
d. Binary search
c. Merge search
b. Linear search
d. Binary search
output : countdown(3)
public static void countdown(int n) {
if (n == 0) {
System.out.println("Done!");
} else {
System.out.println(n);
countdown(n - 1);
}}
3 2 1 Done!
output if fun(5) is printed
public static int fun(int n) {
if (n <= 1) {
return 1;
}
return fun(n - 2) + fun(n - 1);
}
8