April 2018
Intermediate to advanced
408 pages
10h 42m
English
In Chapter 6, Recursions and Reductions, among many others, we looked at how a simple recursion can be optimized into a for loop. We'll use the following simple recursive definition of factorial as an example:

The general approach to optimizing a recrusion is this:
def fact(n: int) -> int:
if n == 0: return 1
else: return n*fact(n-1)