-
What do you call a function that calls itself?
a recursive function
-
What must a recursive algorithm have in order to work?
a condition under which the recursion will stop
-
What do call the situation where a function calls itself directly?
direct recursion
-
What do you call the situation where a function calls another function,
which then calls the original function?
indirect recursion
-
Can you rewrite any recursive function using a loop instead
of recursion?
yes
-
Which is more efficient, a recursive algorithm or a non-recursive algorithm
that does the same thing?
a non-recursive algorithm
-
Write a recursive function that counts down from some number. In other
words, this function prints it's argument, than all numbers down to 1.
def count_down(num):
print(num)
if num > 1:
count_down(num - 1)
-
Write a recursive function that calculates the factorial of a number.
def factorial(num):
if num == 1:
return 1
else:
return factorial(num -1) * num