All language subtitles for 8. Sum of All Even Numbers - Solution

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,660 --> 00:00:01,410 Oh, right. 2 00:00:01,470 --> 00:00:07,390 So I hope you tried to solve this exercise on your own and you came to some conclusion. 3 00:00:07,410 --> 00:00:11,550 So first thing that I would like us to do is just let's not delete it. 4 00:00:12,870 --> 00:00:18,940 Let's basically copied and pasted right here, be it, OK? 5 00:00:18,960 --> 00:00:22,970 So let's say some even numbers. 6 00:00:23,040 --> 00:00:24,680 OK, some even numbers. 7 00:00:24,990 --> 00:00:33,960 So this recursive function is basically going to read and input from the user on every recursive call. 8 00:00:34,200 --> 00:00:40,140 And then what we are going to do is to check if the base condition is satisfied. 9 00:00:40,140 --> 00:00:42,710 If yes, we are going to return again. 10 00:00:42,780 --> 00:00:43,580 Zero. 11 00:00:44,070 --> 00:00:44,520 Right. 12 00:00:44,580 --> 00:00:46,600 Why again are we returning to zero? 13 00:00:47,160 --> 00:00:55,140 That's very simple, because if if we know that we insert minus one, that's the stopping condition. 14 00:00:55,140 --> 00:01:03,480 And the contribution of this final result to the sum of all the even numbers in a sequence is basically 15 00:01:03,510 --> 00:01:04,080 zero. 16 00:01:04,200 --> 00:01:06,240 That's why we return here. 17 00:01:06,300 --> 00:01:14,250 Zero, although a lot of exercises you will see pretty much in this sequence, this exercise is you 18 00:01:14,250 --> 00:01:17,850 are going to see a lot of times a return result of zero. 19 00:01:18,210 --> 00:01:19,970 That's in the base case. 20 00:01:20,010 --> 00:01:25,540 That's not something that is mandatory or that will always occur. 21 00:01:25,560 --> 00:01:32,850 OK, we can have a lot of also a lot of other examples where the result here of the return value will 22 00:01:33,000 --> 00:01:34,500 not be zero. 23 00:01:34,620 --> 00:01:39,730 OK, but maybe we'll we will do also some exercises just like that. 24 00:01:39,900 --> 00:01:40,290 So. 25 00:01:41,510 --> 00:01:47,060 All right, with that being said, let's move on to the important part, because everything up until 26 00:01:47,060 --> 00:01:48,500 now was pretty much the same. 27 00:01:48,500 --> 00:01:55,660 We just modified the function name in the reading of the input was the same and the input from the user, 28 00:01:55,700 --> 00:01:57,660 the stubborn condition was also the same. 29 00:01:58,190 --> 00:02:01,460 And now let us talk about the recursive calls. 30 00:02:01,460 --> 00:02:10,970 Probably here we will have something to modify, something to edit to satisfy the solution for the some 31 00:02:10,970 --> 00:02:12,110 of even numbers. 32 00:02:13,430 --> 00:02:16,310 OK, so recursive calls. 33 00:02:16,880 --> 00:02:24,500 If input user modula two equals to zero, then it's definitely an even number and we would like to do 34 00:02:24,830 --> 00:02:25,100 so. 35 00:02:25,100 --> 00:02:27,560 Previously we done something like this. 36 00:02:27,560 --> 00:02:36,140 We did return one because that was the contribution of this given function. 37 00:02:36,140 --> 00:02:41,660 Call to the count that a total count that we wanted to find out. 38 00:02:42,140 --> 00:02:49,480 And now we don't want to find just the count of the total amount of even numbers we want to find there 39 00:02:49,490 --> 00:02:58,070 sum and the contribution of these function call of this specific function called to the final sum of 40 00:02:58,070 --> 00:03:04,480 all the even numbers in this sequence is basically just to modify this value. 41 00:03:04,520 --> 00:03:07,100 This one with what value? 42 00:03:07,100 --> 00:03:09,780 What do you think should be placed here? 43 00:03:09,800 --> 00:03:11,420 OK, what do you think? 44 00:03:12,230 --> 00:03:21,200 Well, the answer the answer is the input user value, because if that's an even number, then we would 45 00:03:21,200 --> 00:03:32,000 like to add this even value to the final result and then to call another instance of this of this recursive 46 00:03:32,000 --> 00:03:32,480 function. 47 00:03:32,490 --> 00:03:35,390 So let's just modify it because we changed the names. 48 00:03:35,870 --> 00:03:44,720 So if the input is an even number, then return this even number plus the result of the next function 49 00:03:44,720 --> 00:03:46,580 call the next recursive call. 50 00:03:46,910 --> 00:03:55,070 OK, and if that's not the case, we are going basically to return simply to call another recursive 51 00:03:55,580 --> 00:03:57,180 instance of this function. 52 00:03:58,010 --> 00:03:59,960 So I hope that's clear. 53 00:03:59,970 --> 00:04:02,360 Guys, you understand what we are doing. 54 00:04:02,950 --> 00:04:03,440 OK. 55 00:04:04,530 --> 00:04:11,490 And of course, you can again draw everything and all of this solution once again to make sure you understand 56 00:04:11,490 --> 00:04:12,600 everything correctly. 57 00:04:13,830 --> 00:04:20,220 And actually, to be honest, I'm going to do it right away with you, because I think that's a good 58 00:04:20,490 --> 00:04:22,240 thing to help you understand. 59 00:04:22,260 --> 00:04:25,950 So that's our example, one, three, four, six. 60 00:04:26,010 --> 00:04:33,780 OK, so that's the time when we call the first instance of the function, it will be some even let's 61 00:04:33,780 --> 00:04:39,600 call it AC and we are calling this function and we receive from the user the value of one. 62 00:04:40,070 --> 00:04:45,100 OK, and if that's the right value of one, we check this condition is false. 63 00:04:45,120 --> 00:04:52,770 Then we return, we execute the 40 second line and we return the same function. 64 00:04:52,800 --> 00:04:55,200 So we want here to return the result. 65 00:04:55,500 --> 00:04:57,000 That is still unknown. 66 00:04:57,510 --> 00:05:02,730 Right, because the result here is the result of these other function calls. 67 00:05:02,730 --> 00:05:06,570 So this are another function call we are going to call it. 68 00:05:07,330 --> 00:05:10,590 And here we are going to receive another input. 69 00:05:10,590 --> 00:05:17,940 It will be three and we are going to return the result of something that we still don't know, because 70 00:05:18,060 --> 00:05:20,370 that's the result of another function call. 71 00:05:20,380 --> 00:05:22,940 So that's the other function call. 72 00:05:23,250 --> 00:05:25,920 So here we get four. 73 00:05:26,280 --> 00:05:28,620 OK, and if we get here four, right. 74 00:05:28,620 --> 00:05:36,270 That's the example for and if we get four, we simply will check this condition and it will be true 75 00:05:36,330 --> 00:05:37,290 in this case. 76 00:05:37,560 --> 00:05:43,560 Then we are going to return to the input user, which is four plus, then something that we still don't 77 00:05:43,560 --> 00:05:43,760 know. 78 00:05:43,770 --> 00:05:49,380 So that's going to look like this four plus the result of the next function call. 79 00:05:49,830 --> 00:05:54,030 So we are going to make this call again in here. 80 00:05:54,030 --> 00:05:57,470 We will get six as an input. 81 00:05:57,480 --> 00:06:02,430 So six and we know that's also an even number. 82 00:06:02,430 --> 00:06:09,090 And we are going to return from this instance six plus something that we don't know. 83 00:06:09,090 --> 00:06:09,350 Right. 84 00:06:09,360 --> 00:06:13,710 We don't know this the result of this function yet, because that's another function call. 85 00:06:14,310 --> 00:06:19,020 And now we are going to to get here from the user minus one. 86 00:06:19,020 --> 00:06:21,000 Right, because six we've got three. 87 00:06:21,000 --> 00:06:23,240 One oh we got now it's minus one. 88 00:06:23,550 --> 00:06:25,440 So the user inserts minus one. 89 00:06:25,440 --> 00:06:30,390 So predraft please enter a number of user specifies minus one for the final. 90 00:06:31,170 --> 00:06:36,660 And then we read this value and we can see that the base condition, this stabbing condition of the 91 00:06:36,660 --> 00:06:39,600 recursive calls is being satisfied. 92 00:06:40,020 --> 00:06:43,470 And we know that the result return from here is zero. 93 00:06:43,680 --> 00:06:48,180 So zero is returned, six plus zero is six. 94 00:06:48,570 --> 00:06:50,190 So that's the result here. 95 00:06:50,670 --> 00:06:54,840 Four plus six is ten and ten returned also to here. 96 00:06:54,840 --> 00:07:05,010 And finally, the final result, return from all of this chain of calls for this recursive functions 97 00:07:05,280 --> 00:07:06,600 is just ten. 98 00:07:06,930 --> 00:07:16,020 OK, so that's basically all the function calls there that you will have to do in such an example. 99 00:07:16,230 --> 00:07:20,160 OK, so make sure you understand all the concept. 100 00:07:20,160 --> 00:07:27,120 When we are going to call this function into call, make the recursive calls and then when we are going 101 00:07:27,120 --> 00:07:30,540 to get back once we reached some stopping condition. 102 00:07:30,540 --> 00:07:37,020 Because, you know, if these two lines were not here, then this will be just an endless recursive 103 00:07:37,020 --> 00:07:42,720 calls until your memory would would end in your computer. 104 00:07:42,930 --> 00:07:51,720 So these are part of the stopping condition is very important also to always to formulate our correctly, 105 00:07:51,720 --> 00:07:58,080 because a lot of times the problems happen also here and also in the recursive calls, of course. 106 00:07:58,320 --> 00:08:07,530 But yeah, my recommendation is always do some visualization like I'm doing right here with one or two 107 00:08:07,530 --> 00:08:08,180 examples. 108 00:08:08,190 --> 00:08:15,390 Make sure that you reach some some base condition and make sure that the recursive calls are correct 109 00:08:15,390 --> 00:08:16,740 and that and that's there. 110 00:08:17,880 --> 00:08:19,260 And that's the result. 111 00:08:19,550 --> 00:08:23,990 A return from every function, call from every instance is also correct. 112 00:08:24,000 --> 00:08:26,310 That's very, very important. 113 00:08:28,200 --> 00:08:32,920 So, yeah, guys, this is it for this video. 114 00:08:33,360 --> 00:08:35,910 I think we are doing a good progress. 115 00:08:35,910 --> 00:08:37,040 We are proceeding. 116 00:08:37,770 --> 00:08:43,560 I don't know if we are doing, but I guess and I really hope that you are doing a good progress in this 117 00:08:43,560 --> 00:08:48,100 chorus in practice by practicing these examples in these exercises. 118 00:08:49,110 --> 00:08:53,130 So with that being said, my name is Vlad. 119 00:08:53,160 --> 00:08:54,360 This is Alphatech. 120 00:08:54,370 --> 00:09:00,300 Don't forget to leave some review, some comments and feedback to let me know if you like this material 121 00:09:00,300 --> 00:09:03,810 and if you like the course so far and up until now. 122 00:09:03,840 --> 00:09:06,080 So, yeah, thank you. 123 00:09:06,090 --> 00:09:09,150 And we will see each other again soon enough. 124 00:09:09,390 --> 00:09:11,420 Until then, have a great day. 11679

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