Recursion Quiz 3

Last Updated :
Discuss
Comments

Question 1

Which approach does the naive recursive rope cutting problem use?

  • A

    Greedy

  • B

    Divide and Conquer

  • C

    Backtracking

  • D

    Brute-force recursion with all 3 cut choices

Question 2

What is the total number of subsets generated for an array of size n using recursion?

  • A

    n

  • B

    n²

  • C

    2ⁿ

  • D

    n!

Question 3

What is the recurrence relation for solving Tower of Hanoi?

  • A

    T(n) = T(n−1) + 1

  • B

    T(n) = 2T(n−1) + 1

  • C

    T(n) = T(n−2) + 2

  • D

    T(n) = n + T(n−1)

Question 4

What will be the minimum number of moves required to solve Tower of Hanoi for 4 disks?

  • A

    8

  • B

    15

  • C

    16

  • D

    31

Question 5

In the Josephus problem, which of the following correctly represents the recursive solution?

  • A

    J(n) = (J(n−1) + k) % n

  • B

    J(n) = (J(n−1) − 1) % n

  • C

    J(n) = n % k

  • D

    J(n) = k % n

Question 6

For Josephus(n = 5, k = 2), what is the position of the survivor (0-based index)?

  • A

    1

  • B

    3

  • C

    2

  • D

    5

Question 7

What is the time complexity of the naive recursive solution to the Subset Sum Problem?


  • A

    O(n)

  • B

    O(2ⁿ)

  • C

    O(n log n)

  • D

    O(n!)

Question 8

Which technique is used for generating all permutations of a string recursively?

  • A

    Sliding Window

  • B

    Backtracking with swapping

  • C

    Greedy insertion

  • D

    Merge sort

Question 9

The Josephus problem is closely related to:

  • A

    Heap Sort

  • B

    Circular linked list

  • C

    Stack

  • D

    Binary tree traversal

Question 10

What is wrong with the following code?

function permute(str, l, r) {

if (l === r) console.log(str);
for (let i = l; i <= r; i++) {
[str[l], str[i]] = [str[i], str[l]];
permute(str, l + 1, r);
[str[l], str[i]] = [str[i], str[l]];
}
}

permute("abc", 0, 2);


  • A

    Nothing

  • B

    Strings are immutable in JS

  • C

    Infinite Recursion

  • D

    Base case is wrong

There are 10 questions to complete.

Take a part in the ongoing discussion