Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,460 --> 00:00:09,030
Okay, so if he is serious, we know how to how to work with it and how how these serious look like.
2
00:00:09,450 --> 00:00:17,550
And just a quick reminder, we know that the first element F zero equals two, what, two zero and that
3
00:00:17,640 --> 00:00:23,430
F one equals two one and then F two equals two one also.
4
00:00:23,430 --> 00:00:23,730
Right.
5
00:00:23,760 --> 00:00:31,560
The sum of the two previous values and the same goes for F three equals two, F two plus F one.
6
00:00:31,860 --> 00:00:40,260
And this we can specify if one is A and F zero, which is a total of one, and they say is a total of
7
00:00:40,320 --> 00:00:42,480
two and so on and so forth.
8
00:00:42,690 --> 00:00:49,140
And we know that the formula for F there are the anth variable.
9
00:00:49,150 --> 00:00:52,390
The arts are index in the Fibonacci serious.
10
00:00:52,410 --> 00:00:59,520
We'll be equal to half of and minus one plus F, R and of minus two.
11
00:00:59,610 --> 00:00:59,910
Okay.
12
00:01:00,150 --> 00:01:04,630
So that's basically the mathematical explanation behind the serious.
13
00:01:05,160 --> 00:01:14,000
And we want to write a function, a recursive function that will be able to receive this and this index
14
00:01:14,010 --> 00:01:19,140
in these serious r n return of a value add this index.
15
00:01:19,620 --> 00:01:23,880
So one of the ways to do so is to use, first of all, recursion.
16
00:01:23,910 --> 00:01:24,180
OK.
17
00:01:24,240 --> 00:01:28,650
We could solve it using iterations, but we will solve it using the recursions.
18
00:01:28,810 --> 00:01:34,830
And the first thing that we are going to do is to create a function which will be of type end because
19
00:01:34,830 --> 00:01:41,730
we are working with integers here and we will call this function a feedback on Nadji feeB on muchI,
20
00:01:41,740 --> 00:01:42,750
if I'm not mistaken.
21
00:01:42,960 --> 00:01:47,620
And here we are going to specify the index itself that these function will get.
22
00:01:47,680 --> 00:01:54,720
So and specifies that the index and we are looking for the value in this particular index.
23
00:01:55,020 --> 00:01:56,190
So how should we do it?
24
00:01:56,670 --> 00:02:02,280
We know that if we take a look at these are formulated, we had an explanation of the challenge.
25
00:02:02,580 --> 00:02:04,650
We can see that we have here, too.
26
00:02:04,680 --> 00:02:08,340
There are two base cases and the first base cases.
27
00:02:08,790 --> 00:02:15,900
If F if An equals to zero, then the value of this position also will be zero.
28
00:02:16,170 --> 00:02:18,480
So the first condition will look like this.
29
00:02:18,540 --> 00:02:24,570
If if an equals two zero two zero, then return zero.
30
00:02:24,660 --> 00:02:25,230
That's it.
31
00:02:25,380 --> 00:02:35,460
And also another base base case and stubborn condition will be if and if an equals two one, then return
32
00:02:35,460 --> 00:02:35,790
one.
33
00:02:36,120 --> 00:02:36,360
Right.
34
00:02:36,390 --> 00:02:41,490
Because we can see that no mathematical operation is required here.
35
00:02:41,850 --> 00:02:48,360
And from and you know, when N is greater than one, meaning it's two or higher.
36
00:02:48,750 --> 00:02:53,820
Then we should use some formula to find out what will be its result.
37
00:02:54,480 --> 00:02:57,360
And this recursive function, recursive call.
38
00:02:57,600 --> 00:03:05,220
We know that these function, these people not she knows to find the value for these given index and
39
00:03:05,250 --> 00:03:09,380
so feeble, feeble, she knows to find the value at a given index N.
40
00:03:09,780 --> 00:03:12,930
And we know that by by looking at this formula.
41
00:03:12,980 --> 00:03:17,640
This recursive formula, we can say that this function will return.
42
00:03:17,700 --> 00:03:17,970
OK.
43
00:03:18,030 --> 00:03:18,790
So feeble.
44
00:03:18,810 --> 00:03:27,330
Not you for n feeble energy for n will return the feeble energy feeble energy for N minus one plus three
45
00:03:27,360 --> 00:03:27,570
one.
46
00:03:27,570 --> 00:03:28,950
Archie feeble.
47
00:03:29,340 --> 00:03:30,490
Not cheap.
48
00:03:30,560 --> 00:03:32,490
Four and minus two.
49
00:03:32,940 --> 00:03:34,110
Is that clear so far.
50
00:03:34,410 --> 00:03:43,410
We simply take the rules off from the mathematical explanation that we had in the challenge introduction.
51
00:03:43,830 --> 00:03:52,380
We know that f f the Fibonacci value at Index M equals to the Fibonacci value at index N minus one plus
52
00:03:52,440 --> 00:03:53,700
the Fibonacci value.
53
00:03:54,120 --> 00:03:56,790
Add in an index and minus two.
54
00:03:56,910 --> 00:04:00,050
And that's pretty much all that we've written here.
55
00:04:00,060 --> 00:04:03,720
So Fibonacci for an Fibonacci Faran equals two.
56
00:04:03,720 --> 00:04:04,680
Fibonacci four.
57
00:04:05,130 --> 00:04:06,600
And minus one last.
58
00:04:06,600 --> 00:04:08,880
Fibonacci of and minus two.
59
00:04:09,150 --> 00:04:09,750
That's it.
60
00:04:09,810 --> 00:04:16,470
And each of these recursive calls is going to call these function for N minus one and in minus two.
61
00:04:16,710 --> 00:04:23,760
And it's going to be kind of a tree that will return value on every branch until it reaches out some
62
00:04:23,760 --> 00:04:28,950
stopping condition where and equals to zero or M equals to one.
63
00:04:29,580 --> 00:04:30,720
So I hope that's clear.
64
00:04:30,720 --> 00:04:35,250
We are not going to write some main function in this video because it's pretty simple.
65
00:04:35,250 --> 00:04:42,290
Just create some variable and call these function for whatever index you want and bring the result in.
66
00:04:42,330 --> 00:04:50,520
Just open up Wikipedia or Google to compare and see that your printed result is as expected.
67
00:04:50,610 --> 00:04:52,530
So I'll see you in the next challenge.
6265
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.