I am learning recursion nowadays and as the saying goes, the best way to get proficient in recursion is to practice as much as possible. I have a habit of tracing the program in paper (I guess all of us had at some point).
For example, If I had a function like printing a number from 1 to 10:
def print_n():
for i in range(1,11):
print i
I would trace like:
i
.......
1
2
3
4
... and so on
But when I am practicing with recursion, I am finding hard time tracing the program in paper. Can somebody recommend with example a best way to trace recursive function in paper? You can use the following Fibonacci (again!!!) to illustrate your example or you might surprise the readership.
#RECURSIVE FUNCTION TO RETURN Nth FIBONACCI NUMBER
def fib(n):
if n is 0 or n is 1:
return 1
else:
return fib(n-1) + fib(n-2)
