0
Fibonacci - Recursion
I understand how the fibonacci sequence works, but when implementing a fibonacci function - I don't understand what's the given number to the function and what it returns. def fib(n): if n == 0: return 0 if n == 1: return 1 return fib(n - 1) + fib(n - 2)
2 Respuestas
0
Try working out this on pen and paper and visualuze it by tree diagram. ( try on few easy inputs like 1,2,3,4,5 )
You will soon start to see :
f(n)=f(n-1)+f(n-2) for n>=2 and [ f(0)=0 , f(1)=1 ]
That will be much benificial to you!
feel free to ask if you aren't able to
0
Recommend you to learn how recursion works.