You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A recursive algorithm must have a base case, which is a state that tells the recursive function to stop calling itself and return a value
fibonacci numbers
The Fibonacci numbers are a sequence of integers in which the first two elements are 0 & 1, and each following elements are the sum of the two preceding elements:
If you ask fibonacci for the 4th number, it calls itself to get the 3rd number and second number, and adds them together.
it keeps calling itself until it reaches the base case, which in this case is fibonacci(0) and fibonacci(1) since we know we return 1 for this value. Always try to identify the base case.
The higher numbers are "waiting" from the results of lower numbers, so after the base case returns, the stack "unwinds"
fibonacci(4) is equal to fibonacci(3) + fibonacci(2)
fibonacci(3) is equal to fibonacci(2) + fibonacci(1)
fibonacci(2) is equal to fibonacci(1) + fibonacci(0)