I might not be using the correct terminology, but I am rather new to programming (so forgive me if this is an easy search, I am not sure if I am using the correct keywords).
Let's say I have a recurrence relation:
f(0) = 2
f(x) = f(x-1) + 1 for x >= 1.
Now, let's say I want to program this relation using recursion in Python (2.7), but instead of returning just f(x), I want to return a list: [ f(x), f(x-1), ..., f(0) ].
I can easily program the recurrence relation to return f(10):
def my_fun(x):
if x == 0:
return 2
else:
return 1+my_fun(x-1)
However, I am at a loss as of how to return each function call without using a for loop.
Is there a way to do this?
EDIT: I would like to avoid using a for loop if possible.
[f(0), f(1), ..., f(x)]? That would make more sense and is close to dynamic programming or memoization.