Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,410 --> 00:00:06,650
OK, so now that you tried to solve it on your own and the instructions are clear, we are going to
2
00:00:06,650 --> 00:00:09,020
see how this can be solved together.
3
00:00:09,970 --> 00:00:16,580
Let us start with a simple exercise with a simple, ah structure that first of all, we are going to
4
00:00:16,580 --> 00:00:23,050
understand what is basically the type of such a function.
5
00:00:23,660 --> 00:00:29,270
What do you think these function should the return should be of a type in to double flow?
6
00:00:29,450 --> 00:00:30,500
What do you think, guys?
7
00:00:30,950 --> 00:00:38,320
That's very important to understand this part, because usually a lot of people find it difficult to
8
00:00:39,110 --> 00:00:42,920
to make this type of the function.
9
00:00:43,460 --> 00:00:44,300
So what do you think?
10
00:00:45,820 --> 00:00:55,360
Basically, we know that we even don't have the word return in this question, so probably this function
11
00:00:55,360 --> 00:00:57,710
is not going to return anything.
12
00:00:58,450 --> 00:01:05,080
The fact that these function prints some information to the screen does not necessarily mean that these
13
00:01:05,080 --> 00:01:07,230
function should return something right.
14
00:01:07,840 --> 00:01:12,670
So we will assume the type of the function is going to be of a void type.
15
00:01:12,910 --> 00:01:17,830
OK, so void and then rule specified preened one.
16
00:01:17,830 --> 00:01:21,040
I don't know, two n ok, that's the name of the function.
17
00:01:21,460 --> 00:01:23,650
And this function is going to receive.
18
00:01:23,890 --> 00:01:30,730
What do you think it's going to receive some number n so end and OK.
19
00:01:32,050 --> 00:01:41,140
And once this structure is clear, the signature is clear, we are going to run the loop body so the
20
00:01:41,320 --> 00:01:43,840
body will be something like this.
21
00:01:44,410 --> 00:01:48,670
First of all, understand what you are going to do.
22
00:01:49,120 --> 00:01:51,570
I mean, what do you think should be done?
23
00:01:52,150 --> 00:02:00,880
Do you think that if we simply print print f I don't know what percentage D in here, if I m is this
24
00:02:01,300 --> 00:02:02,590
the correct approach.
25
00:02:02,920 --> 00:02:03,820
What do you think guys?
26
00:02:04,790 --> 00:02:08,970
Do you think that if we run the function now, let's just use it here.
27
00:02:09,220 --> 00:02:13,900
So let's just run this print F to N and let's see what happens.
28
00:02:13,910 --> 00:02:19,750
Basically I'm going to solve it together with you and to see all the different different options that
29
00:02:19,750 --> 00:02:23,740
you also may have tried.
30
00:02:23,740 --> 00:02:29,380
And basically some of them worked this way, some worked the other way.
31
00:02:29,380 --> 00:02:30,060
So let's see.
32
00:02:30,340 --> 00:02:35,800
So print one to n that specify for OK as our example.
33
00:02:36,430 --> 00:02:43,120
So if we build and run it now, then in this case what you will see is just the value of four printed
34
00:02:43,120 --> 00:02:43,840
to the screen.
35
00:02:45,130 --> 00:02:46,600
That's not something that you want.
36
00:02:46,600 --> 00:02:50,200
You want all the numbers from one up to four.
37
00:02:50,380 --> 00:02:52,680
So what do you think is missing here?
38
00:02:53,560 --> 00:02:59,500
Basically one of the things that are missing here is the recursive function call.
39
00:02:59,830 --> 00:03:01,780
So let's do it.
40
00:03:03,820 --> 00:03:06,910
And what we need to end now is print.
41
00:03:07,150 --> 00:03:08,770
That's a print one to end.
42
00:03:09,160 --> 00:03:13,300
And if we will specify n here, what do you think will happen?
43
00:03:14,080 --> 00:03:16,510
What do you think will be printed the the screen.
44
00:03:16,510 --> 00:03:18,670
So let's quickly don't write home.
45
00:03:18,670 --> 00:03:21,670
I will build and run it and stop this execution right away.
46
00:03:21,880 --> 00:03:27,640
But you can see that four is printed and less time to the screen.
47
00:03:28,150 --> 00:03:29,140
And why is that.
48
00:03:29,590 --> 00:03:36,520
The reason is very simple because we don't have any stopping condition and the this recursive function
49
00:03:36,520 --> 00:03:43,360
call itself over and over and over and then it prints these n so that's also not something that we want
50
00:03:43,360 --> 00:03:43,870
to happen.
51
00:03:44,290 --> 00:03:46,480
So let's add some stubborn condition.
52
00:03:46,480 --> 00:03:50,980
What should be in this case, the stopping condition in such a case?
53
00:03:51,010 --> 00:03:56,320
The stubborn condition should be basically what do you think?
54
00:03:56,950 --> 00:03:58,780
It should maybe be one.
55
00:03:58,780 --> 00:04:05,200
Right, because we print all the numbers from one up to and from one up to M, so let's make it like
56
00:04:05,380 --> 00:04:06,070
if and.
57
00:04:08,820 --> 00:04:18,990
If is greater or equal to one, then only in this case let us execute these following lines of code.
58
00:04:19,200 --> 00:04:20,970
So let's just copy that.
59
00:04:21,870 --> 00:04:23,430
Copy it here.
60
00:04:23,890 --> 00:04:25,140
Oh, good.
61
00:04:25,740 --> 00:04:26,340
Awesome.
62
00:04:27,180 --> 00:04:29,500
So that's what we will have here.
63
00:04:29,520 --> 00:04:32,150
So do you think anything has changed so far?
64
00:04:33,070 --> 00:04:40,300
Absolutely not, because we still call this function over and over and over again and and will not be
65
00:04:40,300 --> 00:04:41,140
documented.
66
00:04:41,740 --> 00:04:49,610
So what do you think if we had here and minus one right now, what do you think will happen?
67
00:04:50,260 --> 00:04:51,590
What do you think will happen?
68
00:04:51,850 --> 00:04:53,270
Don't try to execute it.
69
00:04:53,290 --> 00:04:58,680
Look at the code and trying to think for yourself what would happen here.
70
00:04:59,590 --> 00:05:05,470
Do you think that this result will be printed to the screen like one, two, three, four, or maybe
71
00:05:05,470 --> 00:05:07,980
some other result will be printed to the screen.
72
00:05:09,190 --> 00:05:12,310
So let's build and run it and see what happens.
73
00:05:13,060 --> 00:05:14,080
So there you go.
74
00:05:14,080 --> 00:05:16,570
You can see four, three, two, one.
75
00:05:17,050 --> 00:05:22,280
Pretty much what we wanted just in some reversed option, right?
76
00:05:22,300 --> 00:05:23,980
We don't want for three to one.
77
00:05:23,980 --> 00:05:25,660
We want one, two, three, four.
78
00:05:26,290 --> 00:05:29,770
So print one to and you can see here and end.
79
00:05:30,250 --> 00:05:36,130
First of all, we print four, then we call this function for four with a value of three.
80
00:05:36,610 --> 00:05:40,510
Then we go print three and then we call it for a two for one.
81
00:05:40,510 --> 00:05:43,690
And then this result is false.
82
00:05:43,690 --> 00:05:48,030
And then basically we stop our recursive calls.
83
00:05:48,340 --> 00:05:48,790
All right.
84
00:05:50,660 --> 00:05:57,560
So that's clear, OK, that we print for three, two, one, want the screen and that's amazing, but
85
00:05:57,590 --> 00:05:59,360
what should you modify?
86
00:05:59,900 --> 00:06:01,580
What should you modify basically?
87
00:06:01,640 --> 00:06:10,990
Remember also this solution, because the solution is can be copied and it can be shown like print and
88
00:06:11,880 --> 00:06:19,040
into one print and one that's the other other solution.
89
00:06:19,070 --> 00:06:26,120
OK, so this function will print all the values from M to A given from A given M to one, and these
90
00:06:26,120 --> 00:06:28,910
function should print all the values from one to M.
91
00:06:28,920 --> 00:06:31,330
So what do you think should be changed here?
92
00:06:31,880 --> 00:06:38,750
And basically what should be changed is probably the order of these two lines.
93
00:06:38,760 --> 00:06:40,960
So flying 15 and 16.
94
00:06:40,970 --> 00:06:43,490
So you should change the order.
95
00:06:43,520 --> 00:06:50,610
Let's try to basically move this line to be printed out after the recursive call.
96
00:06:51,650 --> 00:06:54,170
So this way, what you will do.
97
00:06:54,230 --> 00:06:59,090
OK, let me write with you, OK, so that it will be even clearer to you.
98
00:06:59,660 --> 00:07:02,000
So we are calling with four.
99
00:07:02,030 --> 00:07:03,890
OK, so that's the first instance.
100
00:07:03,890 --> 00:07:09,100
And let's say that's the console application where all the results are going to be printed.
101
00:07:09,530 --> 00:07:12,650
So we call this function with the value of four.
102
00:07:12,950 --> 00:07:17,120
OK, and previously we just printed four and then three to one and so on.
103
00:07:17,540 --> 00:07:20,270
Now we call our call this function with four.
104
00:07:20,270 --> 00:07:21,380
We check this condition.
105
00:07:21,380 --> 00:07:21,980
It's through.
106
00:07:21,980 --> 00:07:24,740
We are going to now call the other function.
107
00:07:25,640 --> 00:07:28,040
Another instance with the value of three.
108
00:07:28,610 --> 00:07:33,980
And then we are going to call these function again with the value of two and then again with the value
109
00:07:33,980 --> 00:07:34,640
of one.
110
00:07:35,510 --> 00:07:42,050
And then what we are going to do is to call this function with the value of zero.
111
00:07:42,290 --> 00:07:44,310
Right, because and minus one is zero.
112
00:07:44,990 --> 00:07:47,630
So we call this function with a zero.
113
00:07:47,660 --> 00:07:51,120
So if any is greater than or equal to one, that's not true.
114
00:07:51,140 --> 00:07:55,920
So this function has been executed and it has not done anything.
115
00:07:56,600 --> 00:07:58,290
So then we go through this function.
116
00:07:58,350 --> 00:08:05,350
OK, this instance, this instance call executed this function of print one to end for zero.
117
00:08:05,360 --> 00:08:05,670
Right.
118
00:08:05,690 --> 00:08:07,820
That was the call for this function.
119
00:08:08,390 --> 00:08:10,340
And this function has been executed.
120
00:08:10,370 --> 00:08:13,190
This line has been executed inside of this instance.
121
00:08:13,500 --> 00:08:15,860
And then we will execute print F percentage.
122
00:08:16,250 --> 00:08:21,700
So we are going to print one to the screen and then these function is over also.
123
00:08:22,580 --> 00:08:27,950
And then we come back to these function, these things dence, these things, those called these print
124
00:08:27,950 --> 00:08:30,990
one, two and four one for this value.
125
00:08:31,010 --> 00:08:37,550
This line has been executed and now we are going to print the given value, the given N, which is two,
126
00:08:37,880 --> 00:08:40,940
and then we are going to do the same for a three and four.
127
00:08:41,060 --> 00:08:46,120
And basically that's what we are expected to see on the screen.
128
00:08:46,490 --> 00:08:48,710
So I hope this is clear to you guys.
129
00:08:48,710 --> 00:08:50,750
Very important, this order.
130
00:08:50,780 --> 00:08:57,830
OK, so if you take a close look at this option right here, you will see that the order is different
131
00:08:57,830 --> 00:09:06,170
between the recursive call and the print command and that this will result in printing all the values
132
00:09:06,170 --> 00:09:08,660
from N to these given one.
133
00:09:08,960 --> 00:09:10,100
OK, is this clear?
134
00:09:10,100 --> 00:09:10,500
Do you.
135
00:09:11,480 --> 00:09:12,080
Awesome.
136
00:09:12,860 --> 00:09:16,910
So let's just once everything is clear to you, right.
137
00:09:16,910 --> 00:09:23,090
Let's just clear this screen and let's basically call this function once again.
138
00:09:23,090 --> 00:09:26,700
So we use our main OK, so print one to him.
139
00:09:27,520 --> 00:09:27,980
Let's see.
140
00:09:27,980 --> 00:09:29,570
Is something even nicer here.
141
00:09:29,570 --> 00:09:31,790
So quick answer and no.
142
00:09:32,540 --> 00:09:35,210
And then the user is going to specify the number.
143
00:09:35,630 --> 00:09:47,520
So it's can f let's use here also some ain't no scam F percent the and story inside the variable.
144
00:09:48,710 --> 00:10:03,980
Now let's say that print have all the values from one to an hour and let's say here all the values will
145
00:10:03,980 --> 00:10:12,080
be printed because we are going to call this function, print one to end and pass the value of NUM.
146
00:10:12,560 --> 00:10:17,450
OK, let's remove this line now with basically build and run it.
147
00:10:18,350 --> 00:10:21,410
So let me just close this before.
148
00:10:21,410 --> 00:10:26,660
OK, so build and run and let's see what's going on.
149
00:10:26,670 --> 00:10:27,900
So enter a number.
150
00:10:27,910 --> 00:10:32,230
So let's say for so all the values from one to an hour.
151
00:10:32,240 --> 00:10:37,550
One, two, three, four on this of course could be replaced with some percentage.
152
00:10:37,940 --> 00:10:39,170
No problem with that.
153
00:10:39,740 --> 00:10:42,320
Let's check it out also for ten.
154
00:10:42,770 --> 00:10:44,830
So let's get it.
155
00:10:44,990 --> 00:10:50,150
Ten all the values from one to M in this case it's ten are one, two, three, four, five.
156
00:10:50,190 --> 00:10:51,550
Six, seven, eight, nine, 10.
157
00:10:51,870 --> 00:10:58,550
So, yeah, this also could be modified like this and here specify now, not a big deal.
158
00:10:59,310 --> 00:11:01,490
So I hope this is clear to you guys.
159
00:11:01,500 --> 00:11:07,230
Also, one thing that we also can modify a little bit is just let's take it like this.
160
00:11:08,130 --> 00:11:09,930
Let's take it like this.
161
00:11:10,650 --> 00:11:15,990
All the values from percentage D to one also created the other way.
162
00:11:17,160 --> 00:11:24,970
And basically we will use here this kind of nice line printer to print and to one.
163
00:11:25,370 --> 00:11:28,940
OK, so let's build it and run it and see what happens next.
164
00:11:29,050 --> 00:11:30,180
So fine.
165
00:11:31,180 --> 00:11:37,590
Or let's just add additional new line here before so that it will be clear.
166
00:11:38,070 --> 00:11:45,360
Print F, so enter a number five and all the values from one to five are one, two, three, four,
167
00:11:45,360 --> 00:11:45,780
five.
168
00:11:45,910 --> 00:11:51,430
And all the values from five to one are five, four, three, two, one.
169
00:11:53,040 --> 00:11:53,610
Hurray!
170
00:11:54,060 --> 00:12:00,480
Congratulations guys for completing these exercise off recursions recursions section.
171
00:12:01,110 --> 00:12:05,670
Not an easy one, but I think that is a very good exercise.
172
00:12:05,700 --> 00:12:07,710
It covers up a lot.
173
00:12:08,490 --> 00:12:14,940
And in the next video we are going to proceed with some variation of this exercise.
174
00:12:15,780 --> 00:12:22,620
And hopefully you will try to solve the next exercise totally on your own because it's going to rely
175
00:12:22,620 --> 00:12:26,100
on the understanding you had to gain in this one.
176
00:12:26,640 --> 00:12:30,090
So with that being said, let me know what you think of this video.
177
00:12:30,090 --> 00:12:30,990
What do you think of this?
178
00:12:30,990 --> 00:12:36,000
Course, it's very important for me to get some feedback from you, to get some review, to get some
179
00:12:36,000 --> 00:12:42,980
comments so that I will know that my hard work is really pays, really pays off.
180
00:12:43,590 --> 00:12:45,000
So thank you, guys.
181
00:12:45,030 --> 00:12:46,580
My name is Vlad Alphatech.
182
00:12:46,590 --> 00:12:47,790
I'll see you next time.
16615
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.