Recursion Quiz 3

Last Updated :
Discuss
Comments

Question 1

Which approach does the naive recursive rope cutting problem use?

  • Greedy

  • Divide and Conquer

  • Backtracking

  • 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?

  • n

  • 2ⁿ

  • n!

Question 3

What is the recurrence relation for solving Tower of Hanoi?

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

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

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

  • 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?

  • 8

  • 15

  • 16

  • 31

Question 5

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

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

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

  • J(n) = n % k

  • J(n) = k % n

Question 6

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

  • 1

  • 3

  • 2

  • 5

Question 7

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


  • O(n)

  • O(2ⁿ)

  • O(n log n)

  • O(n!)

Question 8

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

  • Sliding Window

  • Backtracking with swapping

  • Greedy insertion

  • Merge sort

Question 9

The Josephus problem is closely related to:

  • Heap Sort

  • Circular linked list

  • Stack

  • 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);


  • Nothing

  • Strings are immutable in JS

  • Infinite Recursion

  • Base case is wrong

There are 10 questions to complete.

Take a part in the ongoing discussion