Let's take a look at the Fibonacci sequence.
A Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding numbers.
Right.
So this might be something that you're already familiar with, but let's say we have a function called.
Um, Fibonacci.
And then we accept in as the parameter.
Right.
So we'll say that we want the Fibonacci of six.
If the sequence of numbers is the sum of the two preceding numbers?
Well, we we start out at one and.
Put zero here for clarity.
Zero plus one is one.
Okay, So this is the first number.
This is the second number.
One plus one is two.
So that is our third number.
One plus two is three.
That is our fourth number.
Two plus three is five.
That is our fifth number and three plus five is eight and that is our six number.
So we can say the Fibonacci of six is equal.
To eight.
So the recursion for this would look something like the Fibonacci of N is equal to n plus.
The Fibonacci of N minus one.
Now as an exercise, I would like for you to try to implement the recursion for the Fibonacci sequence,
and I'll give you a hint.
You will need base cases.
And the base cases are is if your number is equal to zero, then return zero.
And if your number is equal to one, then return one.
Right.
So if num equals zero.
Turn zero and then if numb equals one.
Return.
So now take a minute and try to implement this recursive algorithm and check to see how your results
match up to mine.