Embercode
✕
Recursion and BacktrackingQuick quiz

Tail calls and pruning

8 questions. Covers Pruning backtracking.

Questions 1 to 5 of 8

  1. 1. True or false, and why: in this function, the recursive call is in tail position. ``cpp int countUp(int n) { if (n == 0) return 0; return 1 + countUp(n - 1); } ``
  2. 2. True or false, and why: a tail-recursive factorial with 10,000,000 calls runs without a crash when built with plain g++ -std=c++20 -Wall, which uses no -O flag.
  3. 3. True or false, and why: rewriting a tail-recursive function as a loop gives the same answer when the loop reassigns every parameter that the recursive call changed.
  4. 4. The factorial accumulator is written factAcc(n, acc). Which starting value must be passed as acc in the first call, factAcc(5, ?)?
  5. 5. The suffix check in the pruned sum search is written as if (sum + suffix[i] < target) break;. Why is it < and not <=?

5 question(s) left on this page.