Question 41
MediumWhat is the minimum number of moves to solve the Tower of Hanoi with 6 disks?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the minimum number of moves to solve the Tower of Hanoi with 6 disks?
64
36
32
63
Sign up free to see the answer and a step-by-step explanation.
A recursive function has no base case. What happens when it runs?
The compiler removes the recursion
It runs once
It recurses until the stack overflows
It returns 0
Sign up free to see the answer and a step-by-step explanation.
How many times is fib(2) called when computing fib(5) with naive recursion (fib(0) = 0, fib(1) = 1)?
3
4
5
2
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of generating all subsets of n elements by backtracking?
O(2ⁿ) without copying is impossible
O(n²)
O(n × 2ⁿ)
O(n!)
Sign up free to see the answer and a step-by-step explanation.
What is the key step that makes an algorithm 'backtracking' rather than plain recursion?
Using a loop
Using memoisation
Undoing a choice after exploring it, so another choice can be tried
Sorting the input
Sign up free to see the answer and a step-by-step explanation.
What is pruning in backtracking?
Sorting the results
Using a queue
Deleting the input
Skipping branches that cannot lead to a valid solution
Sign up free to see the answer and a step-by-step explanation.
In the subset-sum problem with all positive numbers, when can a branch be pruned?
When the running sum already exceeds the target
Never
After 2 elements
When the sum is even
Sign up free to see the answer and a step-by-step explanation.
Which problem is classically solved with backtracking?
Finding the maximum of an array
Computing a prefix sum
Binary search
Sudoku solving
Sign up free to see the answer and a step-by-step explanation.
What is the space complexity of a recursive DFS that goes n levels deep?
O(log n)
O(n) for the call stack
O(2ⁿ)
O(1)
Sign up free to see the answer and a step-by-step explanation.
How many distinct permutations does the string 'AABC' have?
4
24
12
6
Sign up free to see the answer and a step-by-step explanation.