Recursion 1
Recursion 2
Recursion 3
100

Which word is used to describe a non-recursive sorting or searching algorithm?

Iterative

100

What is the output of the following recursive method call: factorial(4)?

public static int factorial(int n) {

    if (n == 0) return 1;

    else return n * factorial(n-1);

}

a) 24; b) 12; c) 16; d) 8

24

100

What case is constantly repeated until the base case is reached?

a) Constant case

b) Infinite case

c) Case case 

d) Recursive case

Recursive case

200

public class DigitSum {

    public static int sumOfDigits(int n) {

        if (n == 0) { return 0; } 

else { return n % 10 + sumOfDigits(n / 10); }

    }

public static void main(String[] args) {

        int number = 12345;

        System.out.println(sumOfDigits(number)); }

}

What is the function and output of the code?

This Java method recursively calculates the sum of digits of a given integer and the output is 15.

200

What is the stopping condition in a recursive function?

Base case
200

Which of the following is an example of a base case in a recursive method?

A) A method call to itself with modified parameters

B) A conditional statement that returns a value without further recursion

C) A loop that iterates a fixed number of times

D) A mathematical operation involving the method's parameters

A conditional statement that returns a value without further recursion

300

What is parallel recursion?

This concept, often used in recursive algorithms, allows multiple recursive calls to be executed in parallel, typically used in divide-and-conquer algorithms.

300

public static int binarySearch(int[] arr, int target, int left, int right) {

        if (left > right) { return -1; } // Base case: target not found

        //Fill in the missing code

        if (arr[mid] == target) { return mid; }

        else if (arr[mid] > target)  { return binarySearch(arr, target, left, mid - 1); }

        else { return binarySearch(arr, target, mid + 1, right); }

    }

int mid = left + (right - left) / 2;

300

Any recursive solution can be replicated through the use of an iterative approach. True or False?

True

400

_____ track the progress of a recursive function. Fill in the blank.

Parameter values

400

In the following recursive method, how many times will fibonacci be called when fibonacci(5) is executed?

public static int fibonacci(int n) {

    if (n == 0) return 0;

    else if (n == 1) return 1;

    else return fibonacci(n-1) + fibonacci(n-2);

}

A) 5

B) 8

C) 9

D) 15

15
400

Which of the following sorting algorithms is recursive?

  1. Selection Sort

  2. Insertion Sort

  3. Merge Sort

  4. Heap Sort

Merge Sort