All language subtitles for 22. Extra Recursion 1 - Print Sequence of num1s and then Sequence of num2s - Solut.

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,620 --> 00:00:02,990 All right, so where should we start? 2 00:00:03,140 --> 00:00:03,650 OK? 3 00:00:04,160 --> 00:00:10,250 First of all, whenever you get a question in recursion, then what I suggest is, first of all, to 4 00:00:10,250 --> 00:00:11,990 create the signature of the function. 5 00:00:12,560 --> 00:00:18,140 OK, so the signature of the function is going to be the function is going to be of a void type. 6 00:00:18,380 --> 00:00:25,100 Since these function, we do not expect it to return anything, and these functions should only print 7 00:00:25,100 --> 00:00:29,390 some values that a screen, then probably the type of the function should be void. 8 00:00:29,780 --> 00:00:30,360 You agree. 9 00:00:31,100 --> 00:00:31,670 All right. 10 00:00:32,480 --> 00:00:33,830 So let's call this function. 11 00:00:34,130 --> 00:00:34,800 I don't know. 12 00:00:36,170 --> 00:00:37,640 Special sequence print. 13 00:00:37,790 --> 00:00:39,710 Special sequence print. 14 00:00:40,040 --> 00:00:44,400 OK, I don't know exactly what name we should name it, but let's go it with this way. 15 00:00:44,870 --> 00:00:49,340 And as we were requested, the function should receive three integers. 16 00:00:49,430 --> 00:00:50,840 The first one should be total. 17 00:00:51,800 --> 00:01:00,110 We should specify the total length of the sequence of once and twos that are this function is expected 18 00:01:00,110 --> 00:01:00,650 to print. 19 00:01:01,580 --> 00:01:04,370 Then what we are expected to receive is number one. 20 00:01:05,030 --> 00:01:07,520 And finally, int number two, right? 21 00:01:08,830 --> 00:01:09,370 Awesome. 22 00:01:10,000 --> 00:01:14,800 So the first part is complete, we've created the signature for these function. 23 00:01:15,820 --> 00:01:18,580 Now what we want to do is very, very simple. 24 00:01:19,000 --> 00:01:23,440 OK, we want to start thinking about how should we approach it? 25 00:01:24,370 --> 00:01:31,030 So we remember that the previous examples, let's copy these examples right here so that we will have 26 00:01:31,030 --> 00:01:31,270 them. 27 00:01:31,990 --> 00:01:36,430 So for example, if we get a total of three, number one equals two to numb, two equals two four and 28 00:01:36,430 --> 00:01:37,750 then we print this sequence. 29 00:01:38,650 --> 00:01:43,010 So the first thing that comes to mind is let's use some. 30 00:01:43,330 --> 00:01:45,010 We're a loop or while loop. 31 00:01:45,010 --> 00:01:45,760 And that's it. 32 00:01:46,450 --> 00:01:46,810 Right? 33 00:01:47,410 --> 00:01:54,040 Print run this loop over the length of the total print number one. 34 00:01:54,280 --> 00:02:02,560 Then again and again, OK, in some iterations, then to run another loop and to print a sequence of 35 00:02:02,560 --> 00:02:04,360 number two is of this length. 36 00:02:04,550 --> 00:02:05,110 OK, so. 37 00:02:06,720 --> 00:02:13,170 This could be very easy solution to solve this exercise, but this would be not the actual thing that 38 00:02:13,170 --> 00:02:14,280 we were requested. 39 00:02:15,000 --> 00:02:21,240 This would be the iterative approach of using iterations, using for loops, while loops and so on. 40 00:02:22,350 --> 00:02:29,310 We were requested to develop and design a function that should be a recursive function. 41 00:02:29,610 --> 00:02:30,020 OK? 42 00:02:30,150 --> 00:02:32,280 Using the recursion concept. 43 00:02:33,240 --> 00:02:35,310 So that's not how we are going to do it. 44 00:02:37,130 --> 00:02:38,280 We are going, OK. 45 00:02:38,460 --> 00:02:40,320 I'm suggesting this approach, OK. 46 00:02:40,440 --> 00:02:47,300 I'm not sure that it's the best approach, but sometimes also it may be very useful. 47 00:02:47,360 --> 00:02:55,400 OK, I'm going to show you so you will decide for yourself which approach you prefer using, basically. 48 00:02:55,790 --> 00:03:02,540 First of all, understanding the the fullest, what you should do or better say just based on your previous 49 00:03:02,540 --> 00:03:03,190 experience. 50 00:03:03,200 --> 00:03:11,120 Just throw things in the function and try to figure out how it will react and make adjustment to make 51 00:03:11,120 --> 00:03:14,240 it be the exact solution that you want. 52 00:03:14,450 --> 00:03:19,550 OK, so we know that probably OK, we will need to print the value of no one. 53 00:03:20,000 --> 00:03:22,850 And we will also need to print the value of number two. 54 00:03:23,510 --> 00:03:31,910 And probably we should make the recursive call again and again and again until want until we reach total 55 00:03:31,910 --> 00:03:37,640 value that will be of size one, for example, or less, let's say less than one. 56 00:03:37,940 --> 00:03:38,210 OK. 57 00:03:39,020 --> 00:03:43,040 So what we would like to say is that let's run this function. 58 00:03:43,340 --> 00:03:46,220 OK, let's make the print operations. 59 00:03:46,250 --> 00:03:49,220 Let's make the printing functionalities. 60 00:03:49,220 --> 00:03:52,160 Let's make print half and use here. 61 00:03:53,540 --> 00:03:57,290 Let's use higher percentage and then print half number one. 62 00:03:58,040 --> 00:04:00,240 Then let's use print f percentage. 63 00:04:00,560 --> 00:04:01,640 Let's print number two. 64 00:04:02,570 --> 00:04:10,910 Then let's use the recursive function call and let's call it special sequence, print and print. 65 00:04:11,030 --> 00:04:11,480 What? 66 00:04:12,200 --> 00:04:13,340 Total minus one. 67 00:04:15,260 --> 00:04:16,340 As well as no one. 68 00:04:18,530 --> 00:04:19,220 In them to. 69 00:04:20,480 --> 00:04:20,980 All right. 70 00:04:21,710 --> 00:04:23,750 So that's basically what we are going to do. 71 00:04:24,720 --> 00:04:30,600 We are going to use the special sequence print and let's see and try to figure out what it will do, 72 00:04:30,600 --> 00:04:33,390 OK, so we know that first of all, we will need to print them one. 73 00:04:33,960 --> 00:04:35,820 We will also need to print them two. 74 00:04:36,450 --> 00:04:38,820 And we would like to call this function. 75 00:04:39,850 --> 00:04:40,900 Again and again and again. 76 00:04:41,560 --> 00:04:42,670 So what will happen now? 77 00:04:43,090 --> 00:04:44,930 Let's say the total was three. 78 00:04:44,950 --> 00:04:47,050 No one was still and number two was four. 79 00:04:47,500 --> 00:04:50,950 So we printed out two, then we printed out four. 80 00:04:51,950 --> 00:04:57,740 OK, and then we call this function with the value of two and again and again, then probably this function 81 00:04:58,070 --> 00:05:05,060 is going first of all to be want an infinite regulation because there is no stopping condition. 82 00:05:05,510 --> 00:05:12,920 We will call this recursive call again and again and again until the resources of the computer are over. 83 00:05:13,040 --> 00:05:13,460 OK. 84 00:05:14,550 --> 00:05:21,120 So what we would like to do is to say the following let's say if total is greater or equal to one, 85 00:05:21,570 --> 00:05:25,830 then in this case only in this case we will execute this program, right? 86 00:05:26,520 --> 00:05:34,170 So we will say that as long as we did not use the printing operation like it was three and we didn't 87 00:05:34,170 --> 00:05:35,310 use it three times. 88 00:05:36,060 --> 00:05:39,570 So every time that we will call these functions, we will use total minus one. 89 00:05:40,290 --> 00:05:45,990 So once we will run it for a total equal to three, then four two, then four one, and then we will 90 00:05:45,990 --> 00:05:47,910 not run this program again. 91 00:05:48,060 --> 00:05:50,970 Okay, this function will be over because the condition will not be true. 92 00:05:51,630 --> 00:05:58,170 So this way we assured that we printed out a sequence or, let's say, not a sequence. 93 00:05:58,470 --> 00:06:04,350 We made sure that we printed out number one three times through the screen and also number two three 94 00:06:04,350 --> 00:06:05,220 times to the screen. 95 00:06:06,090 --> 00:06:12,900 So if we run this program right now, let's say special special sequence print and we will use total 96 00:06:12,900 --> 00:06:16,860 equal to three number one equals to two and two equals to four. 97 00:06:17,430 --> 00:06:18,940 And we run this program. 98 00:06:19,020 --> 00:06:20,580 Then what we expect to see? 99 00:06:20,880 --> 00:06:23,130 OK, let's hope that it will work. 100 00:06:23,730 --> 00:06:26,970 Then what we will see two four two four two four. 101 00:06:28,110 --> 00:06:34,170 OK, so first of all, we know that no one was printed three times in NAM two was also printed three 102 00:06:34,170 --> 00:06:37,710 times, but that's not exactly what we are looking for. 103 00:06:38,340 --> 00:06:43,770 We are looking to make this sequence of, first of all, printing out the tools and then printing out 104 00:06:43,770 --> 00:06:44,490 the force. 105 00:06:45,790 --> 00:06:51,460 OK, printing out, first of all, number one and then printing out number two, total times. 106 00:06:52,180 --> 00:06:56,620 So if we change the order between these two printouts and we use it like this. 107 00:06:57,990 --> 00:07:03,350 Then probably the result is going to be pretty much the same, just instead of using two for two four, 108 00:07:03,360 --> 00:07:05,760 we will see for a two, for a two, for a two. 109 00:07:06,390 --> 00:07:08,190 It's also not what we are looking for. 110 00:07:08,940 --> 00:07:12,710 So let's try to come up with a good idea and a good solution to this one. 111 00:07:14,090 --> 00:07:18,230 So let's say that we will try to figure out what should happen. 112 00:07:19,430 --> 00:07:26,750 Whenever we try to print it out so we cannot print number one and number two, one after the other before 113 00:07:26,750 --> 00:07:28,160 we make the recursive call. 114 00:07:28,970 --> 00:07:38,150 What we would like to do is to split out, split out the middle, the exact middle of the result, so 115 00:07:38,150 --> 00:07:42,770 that this way we will print out three times or total times, number one. 116 00:07:43,160 --> 00:07:44,930 OK, so number one, printing. 117 00:07:46,190 --> 00:07:48,740 And then we will print number two printing. 118 00:07:50,780 --> 00:07:54,050 And the way to do that is very, very interesting. 119 00:07:55,310 --> 00:08:03,200 We will say that here we will make the recursive call and reduce number one every time until we reach 120 00:08:03,200 --> 00:08:05,510 the time that we printed out total times. 121 00:08:06,410 --> 00:08:14,200 And then when we build our way back in the recursion, OK, we called one instance and then the other 122 00:08:14,200 --> 00:08:14,630 Winstons. 123 00:08:14,630 --> 00:08:18,890 But each of these instances, they printed out the value of number one. 124 00:08:19,940 --> 00:08:22,190 Then they called their recursive call. 125 00:08:23,210 --> 00:08:32,000 But when the recursive call that the called is over, they still will have some commands to complete 126 00:08:32,780 --> 00:08:32,960 in. 127 00:08:32,960 --> 00:08:37,190 These commands should be referred to the printing of number two. 128 00:08:38,380 --> 00:08:39,730 OK, does it make any sense? 129 00:08:40,810 --> 00:08:43,750 Let me show you how it will look like in our code. 130 00:08:44,620 --> 00:08:52,270 So we will place print f percentage number one, then what we would like to do is to call to make the 131 00:08:52,270 --> 00:08:52,990 function call. 132 00:08:53,830 --> 00:08:56,590 And finally, we would like to print number two. 133 00:08:58,320 --> 00:08:59,250 So do you feel me? 134 00:08:59,490 --> 00:09:01,770 Let's say that we have these function. 135 00:09:03,180 --> 00:09:08,610 Right now, OK, we will use F for simplicity with three and two and four. 136 00:09:09,330 --> 00:09:10,710 These function what he does. 137 00:09:10,740 --> 00:09:13,230 OK, let's say that this is the console that we print. 138 00:09:13,500 --> 00:09:18,990 What these function does, it reaches these line prints the result to the screen prints number one. 139 00:09:18,990 --> 00:09:25,320 So it prints two, then these function calls special sequence print, right? 140 00:09:25,470 --> 00:09:29,970 Then it costs special sequence print f for a two, two and four. 141 00:09:31,620 --> 00:09:38,010 These function, these instances, all it does is once again printing out no one, so we print to these 142 00:09:38,010 --> 00:09:38,470 function. 143 00:09:38,490 --> 00:09:42,240 All it does is also calling them special sequence. 144 00:09:42,240 --> 00:09:46,890 Print for now equals to one so f for one, two and four. 145 00:09:48,810 --> 00:09:55,140 So these function, what he does is printing out number one to the screen again, and then we call this 146 00:09:55,140 --> 00:10:00,840 function once again for four want four, f zero, two and four. 147 00:10:01,800 --> 00:10:06,760 Now in this instance, we ask this question if Toto is greater or equal to one. 148 00:10:07,470 --> 00:10:09,150 The answer is no. 149 00:10:09,900 --> 00:10:17,070 So the instances over this condition, the the lines of code related with this condition are not executed 150 00:10:17,070 --> 00:10:18,420 inside of this instance. 151 00:10:19,110 --> 00:10:24,750 Then the instance is over because we executed all the lines of code of these function. 152 00:10:25,290 --> 00:10:27,930 So we say this function is over. 153 00:10:29,470 --> 00:10:30,790 Where did we stop? 154 00:10:31,030 --> 00:10:31,450 OK? 155 00:10:31,480 --> 00:10:32,460 Where did we stop? 156 00:10:32,470 --> 00:10:39,670 We stopped right here, right inside of special sequence print, when total equals to one on one equals 157 00:10:39,670 --> 00:10:41,860 two, two and no two equals two four. 158 00:10:42,880 --> 00:10:46,630 So we stopped a baseline inside of this instance. 159 00:10:47,440 --> 00:10:52,780 All that remains right once we are executed this function, because here it is, it's over. 160 00:10:53,230 --> 00:10:56,500 All that remains now is to print number two. 161 00:10:56,830 --> 00:10:57,880 So we print four. 162 00:10:59,190 --> 00:10:59,910 That's it. 163 00:11:00,180 --> 00:11:00,960 This is done. 164 00:11:01,290 --> 00:11:03,030 And this function is complete. 165 00:11:04,350 --> 00:11:08,940 Who called these fonctionne who called this instance, who called it. 166 00:11:11,040 --> 00:11:16,670 The special sequence print, when Total was equal, Stewart well was equal to two, no one equal to 167 00:11:16,670 --> 00:11:19,220 42 in number two equals to four. 168 00:11:19,880 --> 00:11:24,710 So these function that called these function, that's now they say instance, this now is over. 169 00:11:25,220 --> 00:11:30,200 All that remains for it to do is to use the print percentage, the number two. 170 00:11:30,620 --> 00:11:31,640 So we print four. 171 00:11:31,880 --> 00:11:34,490 And the same we do also four here and we print four. 172 00:11:34,760 --> 00:11:41,060 And this function is over and this line is over and we are ready to move on after we have printed out 173 00:11:41,390 --> 00:11:43,720 this sequence of. 174 00:11:43,730 --> 00:11:50,510 Now, once now, one values off length, total and then number two values of length total. 175 00:11:52,410 --> 00:11:55,120 So I hope this explanation is clear to you guys. 176 00:11:55,140 --> 00:12:02,640 Very, very important to understand it and basically to know how it can be done and how it can be used. 177 00:12:03,150 --> 00:12:04,320 There are a. 178 00:12:05,180 --> 00:12:12,200 A lot of variations that I can basically everybody can make out of this exercise. 179 00:12:12,350 --> 00:12:14,280 OK, maybe some of them. 180 00:12:14,280 --> 00:12:16,690 I will also add additional videos. 181 00:12:16,710 --> 00:12:22,950 OK, and I will not make so dedicated and descriptive explanation of the solution, but I will just 182 00:12:22,950 --> 00:12:31,380 show you the resemblance to this exercise and how basically you should treat exercises of these kind. 183 00:12:32,160 --> 00:12:34,050 So I hope you liked this video. 184 00:12:34,050 --> 00:12:36,840 I hope you like the explanation and the result. 185 00:12:37,230 --> 00:12:38,670 Make sure you understand it. 186 00:12:38,760 --> 00:12:40,480 Try to write it again on your own. 187 00:12:40,500 --> 00:12:42,030 It's not very complicated. 188 00:12:42,030 --> 00:12:48,570 It's not very difficult, but it still requires some attention in some practice. 189 00:12:49,170 --> 00:12:49,500 OK. 190 00:12:49,860 --> 00:12:54,780 Don't go about it and say, OK, I understand everything you said and there is no problem about it. 191 00:12:54,780 --> 00:12:55,470 I will know. 192 00:12:55,920 --> 00:13:00,270 Let's say in the exam or on my job interview, I will know how to do it. 193 00:13:01,350 --> 00:13:03,150 I do not recommend such approach. 194 00:13:03,420 --> 00:13:09,780 What I do recommend is basically closing this solution, trying to solve the exercise on your own, 195 00:13:09,990 --> 00:13:15,210 making sure that it works for various options or, for example, making sure that it will work also 196 00:13:15,210 --> 00:13:15,870 for at least one. 197 00:13:16,260 --> 00:13:19,260 The second example that we had, let's try to run it. 198 00:13:19,860 --> 00:13:26,250 And then when you see that it works at least for three, four or five examples, then compare with the 199 00:13:26,250 --> 00:13:27,600 results I show. 200 00:13:28,140 --> 00:13:29,820 And that's it. 201 00:13:30,180 --> 00:13:32,070 OK, so thank you guys for watching. 202 00:13:32,100 --> 00:13:33,280 Keep on practicing. 203 00:13:33,300 --> 00:13:35,070 Keep on moving forward. 204 00:13:35,100 --> 00:13:35,970 My name is Vlad. 205 00:13:36,300 --> 00:13:38,520 This is alpha tech in until the next time. 206 00:13:38,520 --> 00:13:39,390 I'll see you then. 18893

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.