I want to write a program in Python that illustrates the tree-like nature of recursion. Given a recursive function (for instance fibonacci(n)) there should be a way to print the tree-like call trace of the recursive function. With the following function:
def fibonacci(n): if n == 1 or n == 2: return 1 else: return fibonacci(n-1) + fibonacci(n-2)
The print out for n=5 could look something like:
fibo(5) fibo(4) fibo(3) fibo(3) fibo(2) fibo(2) fibo(1) fibo(2) fibo(1)
The solution should be as "general" as possible and not specific to Fibonacci numbers as I want to implement it for additional recursive functions.