Algorithms from zero
Recursion and backtracking: multiple-choice review
Six questions that cut across the whole unit. Each one is a decision you make when you actually write recursive code, not a definition to recite, but a judgement about correctness, cost, or which fix is right.
Confirm you can connect the four ideas the unit built: a base case and a shrinking recursive case make recursion terminate, the call stack sets space, the recursion tree sets time, and backtracking with pruning turns brute force into something practical.
A recursive function has a base case but still overflows the stack on every input, including tiny ones. What is the most likely cause?
factorial(n) and naive fibonacci(n) both recurse to depth n. Why is factorial fine for large n while fibonacci is not?
A recursive function has branching factor b = 3 and depth d = 12, doing O(1) work per call. Roughly how many calls does it make, and what does that tell you?
In the choose-explore-undo backtracking template, what breaks if you omit the undo step (push to current but never pop)?
Subsets, permutations, and combinations all use the same backtracking template. What actually distinguishes them?
A correct recursive tree-walk works in tests, but a colleague says it must be rewritten iteratively before production. When is that warranted?
The unit’s through-line is one chain: a base case plus a shrinking recursive case make recursion terminate; the call stack makes depth cost O(depth) in space; the recursion tree makes total work the branching factor raised to the depth in time; and backtracking applies that recursive skeleton (choose, explore, undo) with pruning to skip doomed branches. Get the base case and progress right first, then read time from the tree and space from the stack.