ArtOfCode.org
Toggle Menu
Home
Online Rust Compiler
Tutorials
Algorithms 101
Html Css Tutorial
Javascript Tutorial
Blog
All Posts
Recursion and Backtracking
Practice recursive thinking and state space.
1. What is the term for the condition that stops a recursive function from calling itself indefinitely?
Base case
Recursive step
Termination clause
Exit loop
2. Which of the following are common applications of backtracking algorithms?
N-Queens problem
Sudoku solver
Merge sort
Subset sum problem
3. Recursion always results in more efficient memory usage compared to iteration.
True
False
4. What is the process of building a solution incrementally, undoing steps when a dead end is reached, called?
5. In a recursive function, which part contains the logic that calls the function with modified parameters?
Base case
Recursive case
Initialization
Termination check
6. Which of the following are potential drawbacks of recursion?
Stack overflow risk
Redundant calculations
Simpler code readability
Higher time complexity for some problems
7. Backtracking is a form of recursion that explores all possible solutions by incrementally building candidates and pruning invalid paths.
True
False
8. What term describes the maximum number of recursive calls that can be made before causing a stack overflow?
9. Which problem is most commonly solved using backtracking to explore all permutations of elements?
Fibonacci sequence
Permutations of a string
Binary search
Linear search
10. Which of the following problems are typically solved using backtracking?
Graph coloring
Knight's tour problem
Finding GCD
Subset sum problem
11. A recursive function without a base case will eventually cause a stack overflow error.
True
False
12. What technique stores results of expensive recursive calls to avoid redundant calculations?
13. What is the time complexity of the naive (unoptimized) recursive Fibonacci function?
O(n)
O(log n)
O(2ⁿ)
O(n²)
14. Which of the following are key steps in a backtracking algorithm?
Choose: Select the next component of the solution
Explore: Recursively solve the subproblem with the chosen component
Unchoose: Backtrack by undoing the choice if it leads to a dead end
Sort: Order components to optimize exploration
15. Recursion and iteration are mutually exclusive; a problem cannot be solved using both approaches.
True
False
16. In backtracking, what term describes a partial solution that cannot be extended to a valid final solution?
17. Which problem uses backtracking to place non-attacking queens on an n×n chessboard?
Tower of Hanoi
N-Queens problem
Traveling Salesman problem
Binary search
18. Which of the following statements about recursion are true?
Recursion can simplify code for problems with recursive structures (e.g., trees)
Every recursive function must have exactly one base case
Recursion uses the call stack to store function states
Tail recursion can be optimized by compilers to use constant stack space
19. Backtracking is generally more efficient than dynamic programming for problems with overlapping subproblems.
True
False
20. What is the name of the recursive algorithm that moves disks between pegs with the minimum number of moves, following size constraints?
Reset
Answered 0 of 0 — 0 correct