Embercode
✕
Recursion and BacktrackingQuick quiz

Tail calls and pruning

8 questions. Covers Pruning backtracking in Python.

Questions 1 to 5 of 8

  1. 1. True or false: the call in return n * factorial(n - 1) is a tail call.
  2. 2. True or false: CPython turns this tail-recursive function into a loop, so sum_to(10000000, 0) does not raise an error. ``python def sum_to(n, acc): if n == 0: return acc return sum_to(n - 1, acc + n) ``
  3. 3. True or false: pruning cannot change the set of answers, as long as each cut only skips branches that cannot end in a valid answer.
  4. 4. Why is the call factorial_acc(n - 1, n * acc) in tail position?
  5. 5. Why does CPython keep a frame for every call, even for a tail call?

5 question(s) left on this page.