sum to n is n plus sum to n minus 1, with sum to 0 equal to 0. What does sum to 3 return?
Answer: ______________
If you write a recursive function but forget to give it a base case, it will keep calling itself until the program runs out of stack space and crashes.
Circle one: True False
A function is defined as sum_to(n) = n + sum_to(n - 1), with base case sum_to(0) = 0. What does sum_to(3) return?
Answer: ______________
Which line is the base case in count down, where n equals 0 returns done and otherwise it calls count down of n minus 1?
Factorial of n is 1 when n is at most 1, else n times factorial of n minus 1. What is factorial of 4?
Answer: ______________
is_palindrome(s) compares s[0] to s[-1], then recurses on the middle: is_palindrome(s[1:-1]). The base case is when s has 0 or 1 letters. For the word "level", which call hits the base case?
factorial(n) is defined as: if n <= 1, return 1; otherwise return n * factorial(n - 1). What is factorial(4)?
Answer: ______________
Which recursive function does the same job as this loop?
total = 0 for i in range(1, n + 1): total += i return total
power of x, n is 1 when n is 0, else x times power of x, n minus 1. From power of 2, 3, how many calls wait when power of 2, 0 is reached?
is palindrome compares outer letters then recurses on the middle, stopping at 0 or 1 letters. For level, which call hits the base?