Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,180 --> 00:00:10,170
So Lucas numbers what is going on, guys, in this video, we are going to make some exercise about
2
00:00:10,170 --> 00:00:12,960
Lucas numbers and.
3
00:00:14,220 --> 00:00:17,340
That's not a mathematical kuris.
4
00:00:17,340 --> 00:00:18,780
That's a programming course.
5
00:00:18,780 --> 00:00:26,350
We are not going to get into all the details and discuss its relation to the Fibonacci's serious.
6
00:00:26,820 --> 00:00:35,490
We are simply going to talk about a sequence Lucas sequence, let's say, here, Lucas sequence.
7
00:00:36,330 --> 00:00:45,960
And basically the sequence is going to have just some set of rules and we will have to like to implement
8
00:00:45,960 --> 00:00:51,460
it using our programming language and using some recursive method.
9
00:00:51,930 --> 00:00:59,090
So first of all, let us just make a quick recap of what a sequence is actually all about.
10
00:00:59,820 --> 00:01:03,480
And basically, we know let me use the wall.
11
00:01:03,480 --> 00:01:04,350
It's just pink.
12
00:01:05,730 --> 00:01:09,600
So we know that sequence is just.
13
00:01:10,730 --> 00:01:20,000
Sequence is just the set of numbers which have some, let's say, some straight words there in some
14
00:01:20,000 --> 00:01:21,070
base conditions.
15
00:01:21,290 --> 00:01:25,660
So, for example, we have like this sequence one, two, three and so on.
16
00:01:25,670 --> 00:01:29,090
We know that we have the first element is one.
17
00:01:29,090 --> 00:01:31,250
And then the next element is just.
18
00:01:32,600 --> 00:01:40,190
The previous element, plus one, we can also have like two, four, six and so on, each element equals
19
00:01:40,220 --> 00:01:50,570
to the previous element plus two, maybe, maybe like two, four and let's say eight and let's say 16,
20
00:01:50,570 --> 00:01:53,390
which is just the power of the sequence of power.
21
00:01:53,990 --> 00:01:58,340
Basically, there may be a lot of different sequences out there.
22
00:01:58,340 --> 00:02:05,330
And what we are going to do is basically we are going to implement a new sequence that is called the
23
00:02:05,330 --> 00:02:06,770
lucas' sequence.
24
00:02:07,780 --> 00:02:15,100
And this sequence looks like this, so lucas' sequence at index end equals two.
25
00:02:15,400 --> 00:02:20,980
Let's see if and equals to zero, then the value will be two.
26
00:02:21,120 --> 00:02:34,000
OK, so that's if and equals to zero and 11 equals to one if an equal to one and ehl and minus one plus
27
00:02:34,330 --> 00:02:41,300
and minus two if and is greater than one then one.
28
00:02:41,980 --> 00:02:46,830
OK, so that's basically the rules for defining our sequence.
29
00:02:47,440 --> 00:02:52,060
And if we will have we will take a look at for example, how it looks like.
30
00:02:52,070 --> 00:02:57,160
So the first element and equals to zero and is the index.
31
00:02:57,160 --> 00:02:57,670
Right.
32
00:02:57,700 --> 00:02:58,890
That's the index.
33
00:02:59,590 --> 00:03:04,930
So we will see that it's two and then we have one because that's the index of one.
34
00:03:05,440 --> 00:03:12,230
And the next value where I am equals to two will be basically the sum of the two previous.
35
00:03:12,250 --> 00:03:15,430
So it will be three and then it will be four.
36
00:03:15,460 --> 00:03:22,900
Right, because two plus one is three three one plus three, four, three plus four is seven and so
37
00:03:22,900 --> 00:03:24,420
on and so forth.
38
00:03:24,430 --> 00:03:28,030
So that's basically the lucas' sequence.
39
00:03:29,480 --> 00:03:37,570
And what we are going to do right now is simply to write a recursive function that will implement it.
40
00:03:37,790 --> 00:03:45,980
OK, so these function is going to get some in OK, which will represent the index and then it will
41
00:03:45,980 --> 00:03:51,210
find the value of this index using some recursive approach.
42
00:03:51,680 --> 00:03:52,730
So let us start.
43
00:03:52,970 --> 00:03:53,360
OK.
44
00:03:53,390 --> 00:03:57,260
So what do you think should be the type of this function?
45
00:03:57,740 --> 00:04:05,990
Well, basically saying we know that here probably we have at the two base cases we have integers then
46
00:04:05,990 --> 00:04:13,280
probably also for the general case, let's call it this way, when we have like to add the two previous
47
00:04:13,280 --> 00:04:21,590
values and these two previous values probably will also be in the jurors, then in this case, the type
48
00:04:21,590 --> 00:04:24,520
of the function is also probably going to be eight.
49
00:04:25,150 --> 00:04:29,380
So let's say and let's call it like lucas' recursive.
50
00:04:30,530 --> 00:04:35,540
And what we are going to receive is just an which is the index.
51
00:04:35,570 --> 00:04:36,920
OK, awesome.
52
00:04:38,030 --> 00:04:38,560
All right.
53
00:04:38,570 --> 00:04:41,660
So what do you think should happen here?
54
00:04:42,110 --> 00:04:44,480
So basically it's very similar.
55
00:04:44,480 --> 00:04:52,010
If you remember the Fibonacci series that we've made where we have to, first of all, to treat these
56
00:04:52,010 --> 00:04:53,190
two base cases.
57
00:04:53,570 --> 00:04:56,420
So let's start with an equal to zero.
58
00:04:56,430 --> 00:05:01,280
So if an equal to zero, then in this case, what do we know to do?
59
00:05:01,550 --> 00:05:02,630
What do you think?
60
00:05:03,730 --> 00:05:12,010
Basically, we know that two should be returned, right, because the Lucas Valukas sequence at Index
61
00:05:12,040 --> 00:05:14,890
zero should return the value of two.
62
00:05:15,010 --> 00:05:16,770
And that's exactly what we are doing.
63
00:05:17,530 --> 00:05:23,830
And if the index equals to come here and give the index.
64
00:05:24,090 --> 00:05:24,520
Yeah.
65
00:05:24,670 --> 00:05:29,440
And if the index equals to one and in this case, we should return one.
66
00:05:29,800 --> 00:05:37,630
OK, that's not something that I decide to do, you know, like on my own, because that's simply of
67
00:05:38,290 --> 00:05:40,460
the rules for this sequence.
68
00:05:40,480 --> 00:05:43,390
That's exactly how it is defined.
69
00:05:43,420 --> 00:05:52,030
OK, so these are the two base cases which we took care of right now and now.
70
00:05:52,960 --> 00:05:54,640
What do you think that is missing?
71
00:05:54,940 --> 00:05:57,670
What do you think that we didn't take care of?
72
00:05:57,670 --> 00:06:00,170
So let's just use here.
73
00:06:00,250 --> 00:06:01,910
That's something we took care of.
74
00:06:01,930 --> 00:06:03,670
That's also something we do care of.
75
00:06:04,060 --> 00:06:05,320
But what about this?
76
00:06:05,470 --> 00:06:05,880
Right.
77
00:06:06,220 --> 00:06:10,030
This will happen only if and is greater than one.
78
00:06:10,360 --> 00:06:20,260
So assuming that the function is receiving an index, which is a positive number, at least zero or
79
00:06:20,290 --> 00:06:23,670
above, then in this case we will return.
80
00:06:23,800 --> 00:06:24,130
Right.
81
00:06:24,130 --> 00:06:28,420
Because it was not an index zero and it was not an index one.
82
00:06:28,840 --> 00:06:37,180
In this case, we will return the Valukas recursive function for and minus one plus the lucas' recursive
83
00:06:37,180 --> 00:06:38,710
four and minus two.
84
00:06:38,870 --> 00:06:40,990
OK, this will satisfy.
85
00:06:41,350 --> 00:06:44,330
Let me just zoom in a little bit, OK.
86
00:06:45,220 --> 00:06:54,250
This will basically satisfy this condition that al at index end equals to L at the end minus one which
87
00:06:54,250 --> 00:07:00,820
is the Lucasville recursive for M minus one plus lucas' recursive for N minus two.
88
00:07:01,360 --> 00:07:03,490
And basically that's it.
89
00:07:03,820 --> 00:07:07,150
OK, we can simply run this program.
90
00:07:07,170 --> 00:07:22,510
So let's say oh now we have like creative low cost value add index, let's use an index equals to percentage
91
00:07:22,510 --> 00:07:35,500
D also and we will get here at index number and the value will be like Lucas' in cursive at index number.
92
00:07:35,750 --> 00:07:39,930
OK, so let's try to build and run it and see what happens.
93
00:07:40,360 --> 00:07:42,940
Where is the build, build and run.
94
00:07:43,240 --> 00:07:44,220
Answer a number.
95
00:07:44,230 --> 00:07:46,560
So let's start with zero.
96
00:07:46,660 --> 00:07:50,290
So lucas' value at index zero equals to two.
97
00:07:50,590 --> 00:07:51,770
OK, awesome.
98
00:07:51,910 --> 00:07:53,240
That's, that's true.
99
00:07:53,950 --> 00:07:59,820
And now let's try it for the index one Loukas value of the index one equals to one.
100
00:08:01,090 --> 00:08:03,780
So let's see if we can find also these seven.
101
00:08:03,790 --> 00:08:06,100
What is its index is zero.
102
00:08:06,100 --> 00:08:09,140
One, two, three, four, index four.
103
00:08:09,310 --> 00:08:18,400
So let's build and run it and let's use here for so lucas' value at index four equals to seven, which
104
00:08:18,400 --> 00:08:22,930
is pretty much exactly what we have anticipated.
105
00:08:23,830 --> 00:08:28,240
So I think the recursive solution is now complete.
106
00:08:29,120 --> 00:08:36,020
And now, if you still have some questions, feel free to ask them regarding these lucas' recursive.
107
00:08:36,380 --> 00:08:44,110
What I want us to do is simply to make a non recursive solution.
108
00:08:44,120 --> 00:08:45,550
OK, so let's make it.
109
00:08:46,990 --> 00:08:53,140
Additional solution without using recursion recursions again, although it's still in the section of
110
00:08:53,140 --> 00:08:59,530
recursions, but I want you to simply take a look at how these function will look like if we were not
111
00:08:59,560 --> 00:09:01,000
using a recursions.
112
00:09:01,510 --> 00:09:03,680
So get yourself ready.
113
00:09:03,760 --> 00:09:11,920
OK, I think I will leave it in this video to take a few moments, stop this video and try to think
114
00:09:11,920 --> 00:09:14,320
about it, how you can solve this exercise.
115
00:09:14,680 --> 00:09:22,600
These lucas' are sequenced without using the recursion method, but basically try to go back to your
116
00:09:22,600 --> 00:09:31,750
previous mindset that you had like without before using recursions when you were using like iterations
117
00:09:31,750 --> 00:09:35,290
and loops while using for loops, while loops and so on.
118
00:09:35,680 --> 00:09:42,260
So try to think how you would implement this solution and don't skip like to the.
119
00:09:42,610 --> 00:09:46,180
The answer is that I'm about to share with you, try to solve it on your own.
120
00:09:46,190 --> 00:09:47,510
That's very important.
121
00:09:47,860 --> 00:09:55,510
That's the time when you may feel like you're getting a hold of all of the differences between the two
122
00:09:55,510 --> 00:09:58,300
approaches, the recursions and the loops.
123
00:09:58,990 --> 00:10:00,070
So it takes some time.
124
00:10:00,070 --> 00:10:01,810
Guys, stop the video.
125
00:10:01,810 --> 00:10:06,310
And once you're done, let me know and you can go further.
126
00:10:06,340 --> 00:10:08,830
So let's start writing our function.
127
00:10:09,940 --> 00:10:14,290
OK, so these function type is also going to be pretty much the same.
128
00:10:14,320 --> 00:10:18,340
So it's going to be and it's a low class and call it.
129
00:10:18,340 --> 00:10:24,720
I don't know, I'm not not recursive, OK?
130
00:10:25,900 --> 00:10:29,440
It's going to end exactly like previously.
131
00:10:29,830 --> 00:10:33,190
And now we will not have any recursive calls.
132
00:10:33,190 --> 00:10:35,820
We will not have any lucas' recursive.
133
00:10:37,420 --> 00:10:43,520
What do we have to do is basically to understand that two main things should happen here.
134
00:10:43,540 --> 00:10:52,810
So what are the two main things we assume, OK, that the previous value we will start from the bottom
135
00:10:52,810 --> 00:10:53,230
up.
136
00:10:53,360 --> 00:11:00,070
OK, we will assume that the previous value, OK, we will create two values, OK, we will create previous
137
00:11:00,460 --> 00:11:05,500
and we will create current and we will create also temp.
138
00:11:05,530 --> 00:11:07,210
Let me show you what I mean.
139
00:11:07,210 --> 00:11:07,710
Exactly.
140
00:11:08,080 --> 00:11:12,440
So let's first of all, start by defining these two values.
141
00:11:12,460 --> 00:11:20,420
OK, so this will be like eight and three years equals two two.
142
00:11:20,900 --> 00:11:25,060
And then we will also create in current equals to one.
143
00:11:25,300 --> 00:11:27,280
OK, so this will be like two and one.
144
00:11:28,360 --> 00:11:31,510
And what we will ask is pretty much the same question.
145
00:11:31,540 --> 00:11:37,410
If M equals if in equals to zero.
146
00:11:38,320 --> 00:11:38,710
Right.
147
00:11:38,920 --> 00:11:45,370
Just like previously, then in this case we will return the previous book, which is basically the value
148
00:11:45,370 --> 00:11:45,850
of two.
149
00:11:46,180 --> 00:11:48,860
Basically you can return to OK, no problem at all.
150
00:11:49,090 --> 00:11:54,580
So if and equals to one many of these case return one.
151
00:11:54,610 --> 00:12:01,890
OK, so these were just basically the two cases that we needed to take care of and we took care of them.
152
00:12:02,560 --> 00:12:06,940
Now we need to like to calculate every time and to remember.
153
00:12:07,130 --> 00:12:15,370
OK, let me show you that every time that we would like to calculate the lucas' value at index and we
154
00:12:15,370 --> 00:12:22,930
have to remember what was the value, add the previous index as well as what was the value at the previous
155
00:12:22,930 --> 00:12:24,130
of the previous.
156
00:12:24,280 --> 00:12:27,970
OK, so we need to remember always the two values.
157
00:12:27,980 --> 00:12:30,160
So this will be the current.
158
00:12:31,110 --> 00:12:42,260
OK, and this will be in this case for hour two for our two base examples, OK, let me second sorry,
159
00:12:42,660 --> 00:12:48,580
this will be let's start with this will be the previous right or not.
160
00:12:48,960 --> 00:12:56,520
So basically, the solution is a little bit of get lost here because I want to like to give you the
161
00:12:56,520 --> 00:12:59,690
whole picture, but I think I'm doing it the wrong way.
162
00:12:59,700 --> 00:13:02,520
So let's start with the solution.
163
00:13:02,550 --> 00:13:05,140
Using the for a loop, I think it will be easier for you.
164
00:13:05,160 --> 00:13:09,390
So let's start with I let's go.
165
00:13:09,510 --> 00:13:11,320
Let's build our way together.
166
00:13:11,340 --> 00:13:14,060
OK, so for Igbos to do right.
167
00:13:14,100 --> 00:13:19,740
Because we already already took care of index zero and of index one.
168
00:13:20,040 --> 00:13:26,160
So four equals to two as long as I is less than or equal to and I plus plus.
169
00:13:26,700 --> 00:13:32,070
OK, and now what we have to do is to simply calculate some given value.
170
00:13:32,100 --> 00:13:33,750
So how should we do it.
171
00:13:34,760 --> 00:13:40,610
Basically, we should also create additional variable, let's call it, I don't know, let's call it
172
00:13:40,610 --> 00:13:41,930
temp, OK?
173
00:13:42,470 --> 00:13:50,030
And we will say that temp will be equal to the previous value plus the current value.
174
00:13:50,360 --> 00:13:56,320
OK, if we will get like four equals two, we will know that previous is two and current is one.
175
00:13:56,630 --> 00:13:59,780
So we simply got two plus one, which is three.
176
00:13:59,990 --> 00:14:01,520
OK, which is three.
177
00:14:01,550 --> 00:14:04,240
So temp now holds the value of three.
178
00:14:04,940 --> 00:14:09,170
And what we have to update is the previous value.
179
00:14:09,360 --> 00:14:17,810
OK, so the previous value because we have to keep track of both of them L N minus one and L and minus
180
00:14:17,810 --> 00:14:18,200
two.
181
00:14:18,710 --> 00:14:25,640
So the previous value is going to be equal to the current one, which is in this case simply one.
182
00:14:25,680 --> 00:14:26,040
Right.
183
00:14:26,510 --> 00:14:29,210
So each should be equal to current.
184
00:14:30,090 --> 00:14:38,170
OK, so also what we have to update, what do you think for the next iteration.
185
00:14:38,180 --> 00:14:38,440
Right.
186
00:14:38,450 --> 00:14:45,440
So we know that previously we had like this was our what was it previous.
187
00:14:45,860 --> 00:14:47,630
This was current.
188
00:14:48,080 --> 00:14:48,390
Right.
189
00:14:48,390 --> 00:14:50,190
Then we calculated this value.
190
00:14:50,720 --> 00:14:58,160
OK, now we have to update it a little bit so we know that the previous is now should be here and the
191
00:14:58,160 --> 00:14:59,960
current should be here.
192
00:15:00,000 --> 00:15:00,370
Right.
193
00:15:00,710 --> 00:15:06,140
And that's basically why we are going to use current equals to term.
194
00:15:06,950 --> 00:15:07,380
OK.
195
00:15:08,570 --> 00:15:14,090
And then on the next iteration, we are going to calculate this value and this will be the sum of the
196
00:15:14,090 --> 00:15:19,970
previous plus the current, which is previous, plus the current, which will give us four, then you
197
00:15:19,970 --> 00:15:24,260
go and so on and so on until you reach this condition of IGIS.
198
00:15:25,870 --> 00:15:32,500
As long as he is less than or equal to and until this condition is true, you execute this loop and
199
00:15:32,500 --> 00:15:40,750
then basically finally you return the value of current, which is basically will be the final value
200
00:15:40,750 --> 00:15:43,120
that you have calculated.
201
00:15:44,750 --> 00:15:48,330
Who so that was not an easy one to explain.
202
00:15:48,350 --> 00:15:50,020
I hope that's clear to you guys.
203
00:15:50,720 --> 00:15:56,960
And basically we talked about two different approaches to solve and basically to create functions to
204
00:15:56,960 --> 00:16:03,300
find the value at index in a given index in a Loukas sequence.
205
00:16:04,100 --> 00:16:06,440
So I hope that's clear with you guys.
206
00:16:06,440 --> 00:16:07,340
Two approaches.
207
00:16:07,340 --> 00:16:09,020
One, the recursive approach.
208
00:16:09,020 --> 00:16:16,430
The other one is the lucas' non recursive approach to functions to solve one of the same things.
209
00:16:17,210 --> 00:16:20,570
One has its own benefits, one has the other benefit.
210
00:16:21,320 --> 00:16:28,460
Basically, one of the benefits using the recursion is simply that the answer here is just five lines
211
00:16:28,460 --> 00:16:30,370
of code right in the body of the function.
212
00:16:30,380 --> 00:16:34,580
It may also be like minimized to even further to be something like this.
213
00:16:34,580 --> 00:16:34,900
Right.
214
00:16:35,000 --> 00:16:36,470
We can also do it like that.
215
00:16:36,980 --> 00:16:45,290
OK, so it will be three lines of code, but basically we can see that using the non recursive here
216
00:16:45,290 --> 00:16:48,230
is much, much more code.
217
00:16:48,410 --> 00:16:54,600
At least four more lines of code, not drastically more but more.
218
00:16:54,830 --> 00:17:03,200
But regarding the recursion, there are also additional problems that are not being treated, at least
219
00:17:03,200 --> 00:17:04,550
not in this course.
220
00:17:04,810 --> 00:17:07,460
I'm not talking in like in depth.
221
00:17:07,460 --> 00:17:14,090
The memory usage that are a recursive calls can make, for example, if the index here is very, very
222
00:17:15,080 --> 00:17:15,590
high.
223
00:17:15,590 --> 00:17:22,970
So you will have like many, many instances in the memory of your computer and this may cause some problems.
224
00:17:23,480 --> 00:17:26,610
But still, that's a cause for mainly beginners.
225
00:17:26,660 --> 00:17:26,960
Okay.
226
00:17:27,030 --> 00:17:30,070
Not any advanced topics are discussed here.
227
00:17:30,090 --> 00:17:34,060
So basically that's something that you also should bear in mind.
228
00:17:35,360 --> 00:17:37,480
Yeah, and this is it, guys.
229
00:17:37,490 --> 00:17:38,660
My name is Vlad.
230
00:17:38,670 --> 00:17:41,660
This is Alphatech, best course programming.
231
00:17:42,950 --> 00:17:50,720
So thank you so much for watching and make sure to let me know if you have any questions until then.
232
00:17:50,720 --> 00:17:51,770
Next time.
233
00:17:51,770 --> 00:17:53,760
We'll see you next videos.
234
00:17:54,650 --> 00:17:55,280
Bye bye.
21750
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.