PRACTICE • LEARN • GROW
Recursion & Backtracking MCQs
Solve topic-wise placement questions and improve your skills.
Recursion & Backtracking Progress
0 of 37 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the mandatory component of every recursive function that prevents infinite recursion?
A.
Global variable
B.
Base case / condition
C.
Loop statement
D.
Dynamic memory allocation
Explanation & Key
Correct Answer:
2
What error occurs when a recursive function exceeds the maximum allocated call stack memory?
A.
Out of memory (Heap)
B.
Stack Overflow Error
C.
Null Pointer Exception
D.
Deadlock
Explanation & Key
Correct Answer:
3
What is the time complexity of the naive recursive Fibonacci implementation `fib(n) = fib(n-1) + fib(n-2)`?
A.
O(N)
B.
O(N log N)
C.
O(2^N)
D.
O(N^2)
Explanation & Key
Correct Answer:
4
In Backtracking, what is the crucial step performed right after returning from a recursive exploration branch?
A.
Allocating more memory
B.
Reverting / undoing the state change (backtracking step)
C.
Terminating the entire program
D.
Sorting the candidates list
Explanation & Key
Correct Answer:
5
How many total subsets (the power set) does a set of N distinct elements have?
A.
N!
B.
N^2
C.
2^N
D.
2 * N
Explanation & Key
Correct Answer:
6
How many permutations can be formed from a set of N distinct elements?
A.
2^N
B.
N!
C.
N * (N - 1)
D.
N^N
Explanation & Key
Correct Answer:
7
In the classic N-Queens problem, what is the goal of the algorithm?
A.
Place N queens on an N x N chessboard such that no two queens attack each other
B.
Find the minimum moves for a queen to reach all four corners
C.
Capture all pawns using a single queen
D.
Place as many queens as possible on an 8x8 board without rooks
Explanation & Key
Correct Answer:
8
Which technique is used in backtracking to eliminate subtrees that cannot possibly lead to a valid solution?
A.
Hashing
B.
Pruning (Bounding condition)
C.
Memoization
D.
Linear Probing
Explanation & Key
Correct Answer:
9
What is the recurrence relation for the Merge Sort algorithm on an array of size N?
A.
T(N) = T(N-1) + O(1)
B.
T(N) = 2T(N/2) + O(N)
C.
T(N) = 2T(N/2) + O(1)
D.
T(N) = T(N/2) + O(N)
Explanation & Key
Correct Answer:
10
According to the Master Theorem, what is the time complexity of recurrence `T(N) = 2T(N/2) + O(N)`?
A.
O(N)
B.
O(N log N)
C.
O(N^2)
D.
O(log N)
Explanation & Key
Correct Answer:
11
What is "Tail Recursion"?
A.
A recursive function where the recursive call is the final operation executed by the function
B.
Recursion that starts from the end of an array
C.
Recursion with two recursive calls per frame
D.
Recursion that cannot be rewritten iteratively
Explanation & Key
Correct Answer:
12
In solving Sudoku via backtracking, when a guessed digit from 1 to 9 leads to no solution in subsequent cells, what does the algorithm do?
A.
Terminates with no solution immediately
B.
Resets current cell to 0 (empty) and tries the next candidate digit
C.
Restarts from cell (0, 0)
D.
Skips the row
Explanation & Key
Correct Answer:
13
What is the maximum recursion call-stack depth for a balanced divide-and-conquer algorithm on input N (like Binary Search)?
A.
O(1)
B.
O(log N)
C.
O(N)
D.
O(N^2)
Explanation & Key
Correct Answer:
14
What is the time complexity to solve the Tower of Hanoi puzzle with N disks?
A.
O(N)
B.
O(N^2)
C.
O(2^N)
D.
O(N!)
Explanation & Key
Correct Answer:
15
Which of the following problems CANNOT be solved using a standard backtracking search?
A.
Rat in a Maze
B.
N-Queens
C.
Finding Shortest Path in an unweighted graph with optimal BFS linear complexity
D.
Word Search in 2D grid
Explanation & Key
Correct Answer:
16
When generating all unique combinations that sum up to target (Combination Sum), how do we avoid generating duplicate subsets?
A.
Sort the array first and skip identical adjacent elements when starting a new branch
B.
Shuffle the array randomly
C.
Only allow positive even numbers
D.
Limit the recursion depth to 2
Explanation & Key
Correct Answer:
17
What is the difference between Depth First Search (DFS) and Backtracking?
A.
DFS explores all reachable nodes in a graph/tree, while Backtracking is an algorithmic paradigm that systematically constructs and prunes candidate solutions
B.
DFS uses queues while backtracking uses stacks
C.
Backtracking cannot be used on graphs
D.
DFS never uses recursion
Explanation & Key
Correct Answer:
18
What is the space complexity of generating all permutations of an array of size N recursively (excluding the storage of result)?
A.
O(1)
B.
O(N)
C.
O(N!)
D.
O(2^N)
Explanation & Key
Correct Answer:
19
In the Graph Coloring problem, determining if a graph can be colored with at most K colors such that no two adjacent vertices share the same color is:
A.
Solvable in O(V) time using greedy always
B.
An NP-Complete problem solvable using Backtracking in worst-case exponential time
C.
Solvable in O(log V) time
D.
Never solvable using Backtracking
Explanation & Key
Correct Answer:
20
What does the base case return when computing factorial `fact(n)` recursively for `n == 0` or `n == 1`?
A.
0
B.
1
C.
-1
D.
n
Explanation & Key
Correct Answer:
21
What is the maximum recursion depth typically permitted by the standard C++ runtime call stack before a stack overflow segmentation fault occurs?
A.
Infinite, limited only by virtual RAM
B.
Around 10,000 to 200,000 depending on OS stack size (typically 1MB - 8MB)
C.
Exactly 256
D.
Exactly 1,024
Explanation & Key
Correct Answer:
22
In the classic N-Queens backtracking algorithm, how can column and diagonal conflicts be checked in O(1) time?
A.
By scanning the entire board matrix from row 0 to r - 1
B.
Using three boolean arrays / hash sets for col, (row + col), and (row - col)
C.
Using a priority queue sorted by row distance
D.
Using depth-first search on each diagonal line
Explanation & Key
Correct Answer:
23
What is tail call optimization (TCO)?
A.
Converting loops into recursive functions automatically
B.
Reusing the current stack frame when the recursive call is the very last operation executed before return
C.
Pruning recursion branches that exceed a depth of O(log n)
D.
Executing recursive calls in parallel using thread pools
Explanation & Key
Correct Answer:
24
How many total leaf states are generated when finding all permutations of an array of n distinct elements via backtracking?
A.
2^n
B.
n^2
C.
n!
D.
n * (n - 1) / 2
Explanation & Key
Correct Answer:
25
In backtracking, what is the primary purpose of the "un-choose" (backtrack) step?
A.
To free all dynamic heap memory allocated during recursion
B.
To revert the shared state so alternate decision branches can explore from a clean configuration
C.
To terminate the entire recursion tree immediately
D.
To print the current candidate solution
Explanation & Key
Correct Answer:
26
What is the recurrence relation and time complexity of the classic Tower of Hanoi problem with n disks?
A.
T(n) = 2T(n - 1) + 1 => O(2^n)
B.
T(n) = T(n / 2) + O(1) => O(log n)
C.
T(n) = 2T(n / 2) + O(n) => O(n log n)
D.
T(n) = T(n - 1) + O(n) => O(n^2)
Explanation & Key
Correct Answer:
27
Which of the following problems CANNOT be solved using simple divide and conquer without memoization due to overlapping subproblems?
A.
Merge Sort
B.
Computing the n-th Fibonacci number naively
C.
Binary Search
D.
Karatsuba Fast Multiplication
Explanation & Key
Correct Answer:
28
In generating all subsets of a set of size n, what is the total number of subsets and the time complexity?
A.
n subsets, O(n)
B.
n! subsets, O(n!)
C.
2^n subsets, O(n * 2^n)
D.
n^2 subsets, O(n^2)
Explanation & Key
Correct Answer:
29
When solving Sudoku using backtracking, what is the pruning condition for placing a digit d at cell (r, c)?
A.
d must be greater than cell (r-1, c)
B.
d must not already exist in row r, column c, or the 3x3 subgrid containing (r, c)
C.
d must be an even integer if r + c is even
D.
d must equal the sum of neighboring cells
Explanation & Key
Correct Answer:
30
What is the base case in a recursive binary search algorithm?
A.
When lo > hi (target not found) or arr[mid] == target (match found)
B.
When lo == 0
C.
When mid == 0
D.
When hi == arr.length
Explanation & Key
Correct Answer:
31
How does backtracking differ from a brute-force exhaustive search?
A.
Backtracking always runs in polynomial O(n^k) time
B.
Backtracking prunes partial candidates as soon as they violate constraints, avoiding exploration of their entire subtrees
C.
Backtracking does not use recursion
D.
Backtracking only works on sorted arrays
Explanation & Key
Correct Answer:
32
In the Word Search problem on an m x n board, what prevents the recursive search from reusing the same character cell multiple times in a single word?
A.
Deleting the cell from the board vector permanently
B.
Temporarily modifying the cell (e.g. board[r][c] = '#') and restoring it during backtrack
C.
A single global counter
D.
Sorting the board alphabetically
Explanation & Key
Correct Answer:
33
What is the time complexity of generating all valid combinations of n pairs of balanced parentheses?
A.
O(2^n)
B.
O(n!)
C.
O(4^n / sqrt(n)), bounded by the n-th Catalan number C_n
D.
O(n^3)
Explanation & Key
Correct Answer:
34
What is the state transition invariant when generating permutations of an array containing duplicate elements?
A.
Sort array first; skip duplicate element if nums[i] == nums[i-1] and nums[i-1] has not been used in current branch
B.
Use a random shuffle before each permutation
C.
Reverse the array after every odd swap
D.
Duplicate arrays cannot be permuted with backtracking
Explanation & Key
Correct Answer:
35
What is indirect recursion?
A.
A function that calls another function which in turn calls the first function
B.
A recursive function that has no base case
C.
A function that returns a lambda expression
D.
A loop that replaces recursion
Explanation & Key
Correct Answer:
36
What auxiliary space is consumed by a recursive function with depth d where each frame allocates 64 bytes of local variables?
A.
O(1)
B.
O(d) auxiliary call stack space
C.
O(d^2)
D.
O(log d)
Explanation & Key
Correct Answer:
37
In the Subset Sum problem, what greedy heuristic can be applied to optimize backtracking branch pruning?
A.
Sort numbers descending so larger numbers exceed the target sum faster, triggering earlier pruning
B.
Sort numbers ascending so no branches are pruned
C.
Randomize the numbers
D.
Multiply all numbers by 2
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong