All language subtitles for 13. Finding Maximum Value in a Sequence of Elements (Using Recursion)

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,520 --> 00:00:07,480 What is going on, ladies and gentlemen, this exercise, what we are going to do is simply to write 2 00:00:07,480 --> 00:00:12,600 a function, a recursive one that will get some number. 3 00:00:12,610 --> 00:00:15,160 OK, so recursive function, right? 4 00:00:15,280 --> 00:00:20,080 Because we are at a recursive section recursions. 5 00:00:20,080 --> 00:00:25,990 So recursive function that will get that will get some on natural. 6 00:00:25,990 --> 00:00:28,000 No, let's say no. 7 00:00:28,810 --> 00:00:40,950 OK, and this function will receive, you will receive OK and read a sequence, read a sequence of no 8 00:00:41,320 --> 00:00:43,660 numbers from the user. 9 00:00:44,710 --> 00:00:55,480 And finally this function should the return return of the maximum value in the sequence. 10 00:00:55,810 --> 00:01:06,100 OK, guys, so recursive function to get some r some num values from the user, a sequence of num values 11 00:01:06,100 --> 00:01:09,190 from the user and basically to return the maximum. 12 00:01:10,330 --> 00:01:14,020 So take a few moments, think about how these can be solved. 13 00:01:14,140 --> 00:01:23,500 OK, basically I know that some of you may be thinking to yourself like and find marks and get some 14 00:01:23,500 --> 00:01:36,400 number and then simply to use like I don't know while let's define basically while and arm is greater 15 00:01:36,400 --> 00:01:37,300 than let's say. 16 00:01:39,100 --> 00:01:45,970 Then zero, then in this case, simply use some kind of function and read and return the maximum. 17 00:01:46,000 --> 00:01:52,920 OK, so this will be right and these will probably solve it if you are going to use the territory approach. 18 00:01:53,260 --> 00:02:01,690 But nevertheless, we are using here and we need to create a recursive function because that's basically 19 00:02:01,690 --> 00:02:03,870 the instructions for this exercise. 20 00:02:04,420 --> 00:02:09,730 So and find mux in some of these signature is all right. 21 00:02:09,910 --> 00:02:18,280 We are not going to use the wild things here, but we are going to make some basic condition and we 22 00:02:18,280 --> 00:02:20,830 are going to make some recursive calls. 23 00:02:20,920 --> 00:02:24,970 OK, so take a few moments, think about how it can be solved. 24 00:02:24,970 --> 00:02:29,070 And once you're back, we are going to continue and solve it together. 25 00:02:30,540 --> 00:02:33,780 So that's actually not a very easy task. 26 00:02:33,910 --> 00:02:40,660 OK, because you see this exercise is not considered to be so trivial. 27 00:02:41,280 --> 00:02:48,200 So what I recommend you when you start working on these exercises is basically to start with some example. 28 00:02:48,540 --> 00:02:52,860 So let's say let's say none will be equal to three. 29 00:02:53,250 --> 00:03:00,690 And the sequence is going to be like one three into OK, that's going to be the sequence. 30 00:03:02,190 --> 00:03:04,240 So what do you have to do? 31 00:03:04,290 --> 00:03:08,900 I think that the best approach is simply to start with some drawing. 32 00:03:08,910 --> 00:03:13,110 OK, so we know that probably that's going to be the case. 33 00:03:13,140 --> 00:03:17,280 OK, so one, two, three and let's say four. 34 00:03:17,840 --> 00:03:20,430 OK, so that's going to be the case. 35 00:03:21,550 --> 00:03:28,740 And we know that we have to like to first of all, to call this function for number equals to three 36 00:03:29,310 --> 00:03:30,990 now equal to two. 37 00:03:32,270 --> 00:03:38,810 Now I'm equal to one, and that's basically, I don't know, now equal to zero, which is does which 38 00:03:38,810 --> 00:03:47,180 does not satisfy the base condition of the base condition is false. 39 00:03:47,540 --> 00:03:47,960 OK. 40 00:03:49,120 --> 00:03:53,500 All right, and now what do we have to do simply to read some input here? 41 00:03:53,670 --> 00:03:59,400 OK, here will be an input from the user and here will also be an input from the user. 42 00:03:59,620 --> 00:04:02,340 And also here will be some input from the user. 43 00:04:03,070 --> 00:04:07,540 And we have finally, finally the final result. 44 00:04:07,750 --> 00:04:09,490 We have to return. 45 00:04:10,780 --> 00:04:11,740 The maximum. 46 00:04:13,910 --> 00:04:22,850 OK, so we need to make like to make sure that we understand that we understand how to compare between 47 00:04:22,850 --> 00:04:24,300 these different inputs. 48 00:04:24,320 --> 00:04:29,140 So let's say that's input A, B and C and so on. 49 00:04:29,150 --> 00:04:32,500 There may be also D, E, F and so on and so forth. 50 00:04:33,350 --> 00:04:38,750 So we need to think of some way of how we can compare between. 51 00:04:39,840 --> 00:04:49,130 Are the previous input to the current input and basically to every time that we return from a recursions 52 00:04:49,140 --> 00:04:53,280 or for example, we are going to return accuracy because that's the maximum. 53 00:04:53,290 --> 00:05:00,300 But from here to here, we are going to return the maximum between B and the maximum so far. 54 00:05:00,300 --> 00:05:06,970 And from here, we are going to return the maximum between an input A and the maximum received so far. 55 00:05:07,060 --> 00:05:13,830 OK, so that's very important to take into consideration the fact that we want to like to take into 56 00:05:13,830 --> 00:05:16,740 account the maximum. 57 00:05:17,950 --> 00:05:19,090 The maximum. 58 00:05:20,190 --> 00:05:21,200 Value. 59 00:05:22,540 --> 00:05:27,420 So far, OK, so that's also very important. 60 00:05:29,630 --> 00:05:31,310 So how should you solve it? 61 00:05:31,610 --> 00:05:34,590 How should we basically treat this exercise? 62 00:05:35,090 --> 00:05:40,610 So basically, let's start and talk about the base condition, OK? 63 00:05:40,670 --> 00:05:48,530 And the base condition is going to be as long as numb is greater than one, right? 64 00:05:48,770 --> 00:05:54,770 As long as that's the case, because we know that we want just the sequence of numb numbers are received 65 00:05:54,770 --> 00:05:55,460 from the user. 66 00:05:55,460 --> 00:06:01,080 And every time we are simply going to like to decrease it by one and make the recursive call. 67 00:06:01,100 --> 00:06:08,420 So if that's the case, then what we have to do, what do we have to do? 68 00:06:09,230 --> 00:06:15,440 We have to create additional variable and let's call it blocks so far. 69 00:06:15,530 --> 00:06:26,240 OK, this variable, OK, this variable will be used to check OK to check into received the value of 70 00:06:26,600 --> 00:06:28,250 just go down a little bit. 71 00:06:28,640 --> 00:06:36,240 OK, so that everything will be seen so much so far will be equals to find marks for now minus one. 72 00:06:36,980 --> 00:06:38,390 And what do I mean by that. 73 00:06:38,570 --> 00:06:40,400 OK, let me just a little bit. 74 00:06:41,990 --> 00:06:42,870 Erase it. 75 00:06:43,680 --> 00:06:53,660 OK, what do I mean by that, basically marks so far will be the maximum received so far from the previous 76 00:06:53,810 --> 00:06:55,050 recursion calls. 77 00:06:55,460 --> 00:07:01,450 OK, and also what these find marks is going to return. 78 00:07:01,460 --> 00:07:04,340 It also has to receive some input from the user. 79 00:07:04,340 --> 00:07:04,620 Right. 80 00:07:04,640 --> 00:07:11,780 So let's get some input, user user input, you user input. 81 00:07:12,350 --> 00:07:14,900 And now let's bring some nice message to the screen. 82 00:07:14,900 --> 00:07:18,710 So primitive enter into an input. 83 00:07:21,270 --> 00:07:28,690 Scan a scan of percentage and read this important story inside of the variable user input. 84 00:07:29,710 --> 00:07:37,740 And now once we have the user input and we have the mux values, so far, what we have to do is simply 85 00:07:38,130 --> 00:07:40,110 to ask the following question. 86 00:07:40,650 --> 00:07:52,620 If the user input in this case in these are recursive function call is greater than maximum value so 87 00:07:52,620 --> 00:07:53,140 far. 88 00:07:53,640 --> 00:07:58,790 So if that's the case, then what should we return from this function? 89 00:07:59,250 --> 00:08:05,870 We should return the user input because that's the maximum so far from this point. 90 00:08:06,540 --> 00:08:14,760 And if not, we are going to return what the maximum value so far received in the previous calls. 91 00:08:15,310 --> 00:08:17,880 OK, so is it clear to you guys? 92 00:08:18,210 --> 00:08:21,140 Do you see this picture? 93 00:08:21,150 --> 00:08:24,120 Do you see how it basically looks like? 94 00:08:24,870 --> 00:08:29,190 So if none is greater than one, then that's what happens. 95 00:08:31,280 --> 00:08:31,760 All right. 96 00:08:31,940 --> 00:08:40,070 And one of the main questions that we haven't solved yet, but I think that we will right away let's 97 00:08:40,070 --> 00:08:44,010 start and basically run this example together. 98 00:08:44,780 --> 00:08:48,200 So for that, let us use our amazing pen. 99 00:08:48,650 --> 00:08:53,120 So for a number equal to three, we get an input of one. 100 00:08:53,360 --> 00:08:55,190 OK, so that's the input of one. 101 00:08:56,120 --> 00:08:59,910 And then we will ask Max so far, find Max. 102 00:08:59,930 --> 00:09:01,040 OK, so we go here. 103 00:09:01,250 --> 00:09:07,820 We read again the input and the input is three, OK, and then we call the max so far for these function, 104 00:09:07,820 --> 00:09:08,840 we don't know it yet. 105 00:09:08,840 --> 00:09:09,110 Right. 106 00:09:09,110 --> 00:09:17,600 We don't know the value of Max so far because it's going to be received from this function and this 107 00:09:17,600 --> 00:09:21,020 function does not know also the max so far until this point. 108 00:09:21,030 --> 00:09:24,320 So it's going also to be received from fine max for one. 109 00:09:24,890 --> 00:09:30,680 And this one doesn't know either Max so far and is going to receive it from this one. 110 00:09:30,810 --> 00:09:39,410 OK, the value here is to and here we know that that of a user input is going to be what? 111 00:09:40,750 --> 00:09:47,170 What it's going to be, it's not going to we are going to read any input from the user, but the question 112 00:09:47,170 --> 00:09:51,490 is if that's also OK, what do you think guys want? 113 00:09:51,490 --> 00:09:54,580 What happens here is this condition. 114 00:09:54,790 --> 00:10:00,460 Take a few moments, a few minutes even to think about it is this condition is OK. 115 00:10:01,590 --> 00:10:09,850 If none is greater than one, then will we reach even in the first place to this now equals to the zero. 116 00:10:10,270 --> 00:10:11,070 What do you think? 117 00:10:11,500 --> 00:10:12,880 What do you think guys? 118 00:10:15,000 --> 00:10:22,530 And of course, the solution is definitely not because this condition will never reach these now equals 119 00:10:22,530 --> 00:10:31,890 to zero, since this if none is greater than one, OK, will not be applied on this one because none 120 00:10:31,890 --> 00:10:35,190 equals to one and it's not greater to one than in this case. 121 00:10:35,190 --> 00:10:38,390 We will not ask for marks so far. 122 00:10:38,420 --> 00:10:40,280 OK, so that's something we can remove. 123 00:10:40,800 --> 00:10:46,890 OK, so the stubborn condition, the base condition is a little bit different than what I've drawn here. 124 00:10:47,190 --> 00:10:54,600 And the reason is very simple because I wanted you to think of the solution and to understand the base 125 00:10:54,600 --> 00:11:01,320 case, the actual base case and the actual base case is once we reach the final input. 126 00:11:01,510 --> 00:11:10,400 OK, so once we reach the final input, which is this one in this case, OK, that's the final input, 127 00:11:10,410 --> 00:11:10,750 OK. 128 00:11:10,770 --> 00:11:19,050 The last input from the user in the last input, we know that the maximum so far until this point is 129 00:11:19,050 --> 00:11:21,140 basically just the value of the input. 130 00:11:21,150 --> 00:11:21,390 Right. 131 00:11:21,390 --> 00:11:26,700 Because there are no any recursive calls after that. 132 00:11:27,270 --> 00:11:31,820 So that's why we have the final input as the value of two. 133 00:11:32,700 --> 00:11:35,740 And what we have to return this condition is false. 134 00:11:36,060 --> 00:11:37,640 So nothing will be returned? 135 00:11:38,040 --> 00:11:39,150 No, of course not. 136 00:11:39,420 --> 00:11:45,720 But we know that the maximum so far that should be returned is just the user input in this case. 137 00:11:45,930 --> 00:11:48,960 OK, so what will happen next? 138 00:11:49,110 --> 00:11:55,710 OK, once we go back, so from this recursive call, we return the user input because this condition 139 00:11:55,710 --> 00:11:56,510 was not true. 140 00:11:56,880 --> 00:11:59,780 So Mark so far will be to in this case. 141 00:12:00,330 --> 00:12:07,650 And then we ask if user input is greater and is greater than the mark so far in this case, return the 142 00:12:07,650 --> 00:12:08,340 user input. 143 00:12:08,370 --> 00:12:11,610 So here we are going through a three in here. 144 00:12:11,850 --> 00:12:14,760 In this instance, we are going to check it out again. 145 00:12:14,760 --> 00:12:21,410 And to see if three is less than half the mark so far is less than user input. 146 00:12:21,840 --> 00:12:28,200 If that's the case, we are going to what we are going to basically Mark so far here is greater than 147 00:12:28,200 --> 00:12:28,900 the user input. 148 00:12:29,230 --> 00:12:34,110 Now, that's why we are going to return three as the final result. 149 00:12:35,400 --> 00:12:41,280 So very important to understand all of these concepts, guys, all of these steps. 150 00:12:41,790 --> 00:12:45,030 This exercise is not an easy one. 151 00:12:45,030 --> 00:12:46,610 It's not straightforward. 152 00:12:46,830 --> 00:12:51,750 OK, try to write also by yourself a few examples. 153 00:12:51,750 --> 00:12:54,450 Try to think about it, how you should call it. 154 00:12:54,450 --> 00:12:55,200 Why is this? 155 00:12:55,230 --> 00:13:01,980 The condition is exactly as it is trying maybe to think also if there are maybe some other solutions 156 00:13:02,850 --> 00:13:05,550 that may come to your mind and. 157 00:13:06,740 --> 00:13:12,290 Basically, what I suggest may be maybe, maybe let me think about it. 158 00:13:12,920 --> 00:13:14,610 Mm hmm. 159 00:13:15,170 --> 00:13:22,520 Maybe in the next exercise, just to make everything more clear and as clear as possible to you in the 160 00:13:22,520 --> 00:13:28,790 next exercise, once you practice this one also on your own, in the next exercise, we are going also 161 00:13:28,790 --> 00:13:30,260 to find the minimum. 162 00:13:30,410 --> 00:13:34,300 OK, so instead of finding the maximum, we are going to find the minimum. 163 00:13:34,640 --> 00:13:41,540 But the importance in the next exercise is that you will try again to do it on your own and to make 164 00:13:41,540 --> 00:13:43,340 sure that it works by running. 165 00:13:43,340 --> 00:13:52,160 Also some void mean and with a couple of scenarios and to see that everything works exactly as you expected. 166 00:13:53,990 --> 00:13:55,670 So thank you guys for watching. 167 00:13:55,700 --> 00:13:56,840 My name is Vlad. 168 00:13:56,870 --> 00:13:57,940 This is Alphatech. 169 00:13:57,950 --> 00:14:05,180 I'm really enjoying teaching you these very amazing material that may help you in your studies, whether 170 00:14:05,180 --> 00:14:10,850 you're a student, I don't know, in school, in college and university, or basically you're just the 171 00:14:10,850 --> 00:14:14,660 self employed or C programming developer. 172 00:14:14,660 --> 00:14:15,920 That's also an option. 173 00:14:16,760 --> 00:14:19,220 And yeah, I hope you like it. 174 00:14:19,220 --> 00:14:21,680 And I'll see you in the next videos. 16834

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