1
00:00:00,080 --> 00:00:05,840
Let's now get into the code and write the recursive solution for finding the Fibonacci number.

2
00:00:05,870 --> 00:00:08,300
Okay, so we are given n over here.

3
00:00:08,300 --> 00:00:15,380
Now the base case would be that if n is less than or equal to one, then we can just return n itself,

4
00:00:15,380 --> 00:00:15,620
right?

5
00:00:15,620 --> 00:00:18,860
Because if n is zero then we just return zero.

6
00:00:18,860 --> 00:00:24,080
And if n is one, we just return one because we know that the Fibonacci series goes like that, right?

7
00:00:24,080 --> 00:00:28,130
We have zero, then we have one, then we have zero plus one, which is one.

8
00:00:28,130 --> 00:00:32,990
Then we have one plus one which is two, and the next one would be one plus two which is three.

9
00:00:32,990 --> 00:00:34,460
And it goes on in this manner.

10
00:00:34,460 --> 00:00:34,850
Okay.

11
00:00:34,850 --> 00:00:45,050
So the base case over here is if n is less than or equal to one, then we can just return n itself.

12
00:00:45,050 --> 00:00:53,780
Now if this is not the case then we can return Fibonacci n minus one plus Fibonacci n minus two.

13
00:00:53,810 --> 00:00:54,140
Okay.

14
00:00:54,140 --> 00:01:00,860
So for that we will be recursively calling the fib function with the inputs n minus one and n minus

15
00:01:00,860 --> 00:01:01,190
two.

16
00:01:01,220 --> 00:01:01,850
Okay.

17
00:01:01,850 --> 00:01:02,600
So that's it.

18
00:01:02,600 --> 00:01:04,310
Now this is the recursive solution.

19
00:01:04,310 --> 00:01:09,380
Now let's go ahead and run this code and see if it's passing all the test cases okay.

20
00:01:09,380 --> 00:01:10,790
So this is the recursive case.

21
00:01:11,210 --> 00:01:12,230
So let's run it.

22
00:01:13,670 --> 00:01:16,670
And you can see that it's passing all the test cases.
