While studying from the book Algorithms by Michael Goodrich I came upon this "different than usual" recursive algorithm to compute the nth Fibonacci number. The algorithm isn't much explained in the book and the only answer I come up with is (1,1) .
def fibonacci(n):
if n<=1:
return (n,0)
else:
(a,b) = fibonacci(n-1)
return (a+b,a)
print(fibonacci(5))
It does work perfectly but I just can't understand how is it working and I do know how recursion works . Any help would be appreciated thanks.