All language subtitles for 2. Recursive Function - Total Numbers Less Than Num - Solution

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

Original subtitles

All right, so now that you've tried to solve it on your own, let's do this together.

And the first step that we need to to take is to understand the signature of the function.

So let's say that we will decide on a name, let's say total smaller, let's call this function and

what this function should return.

Basically, we know that these function returns some count value, right?

Either it's zero one, two or three and so on.

So the type of the function is going to be int and we will say total smaller.

OK, and the function, of course, is going to receive just in this case, one integer value and it

is going to be not so in total smaller int num.

Awesome.

And now what we are going to do is to read OK, and basically to understand what we want to do.

We want to read from the user some values right up until the user inserts minus one.

But we cannot do it in some approach like this do while or while we cannot use the interactive approach,

we have to use some recursive concept.

And that's basically guys, where a lot of students have a hard time and also I as I remember myself,

I really had it like like it was not it was not so trivial.

It was not so easy to to grasp this concept at first.

But still, there is nothing we can do.

So we need to somehow to solve it together.

So let's try to think about it.

And let's start with the fact that we will try to basically read from the user, OK, on every recursive

call, we will try to read some value.

OK, we'll start.

Let's start ups.

Let's start with this one.

OK, so that's the recursive call.

And we will see or here an example like I don't know, let's call it first first call and we will read

on this call some input from the user.

OK, so we will read it.

Look what happened.

OK.

Oh OK.

So we will read it so into the input user and we will specify some descriptive message.

Please enter a number, OK, and then we will read this information into this input user variable.

So that user awesome.

And now what we have to ask is basically he's basically.

Let's let's consider the the terminating condition, which is minus one, so if the input user input

user equals two minus one, then what can we conclude out of it?

We can say that if the user has inserted minus one, then the contribution of this input of these given

input to the total number of values smaller than this number, what is the contribution?

It's zero.

Right.

We don't take it into consideration.

So that's why we will return zero.

OK, if the input user equals to minus one, then we don't care about it.

But otherwise, if the input of the user, if the input of the user, if input user is less than num,

then in this case this recursive call to this function should add one one, a value of one to the total

numbers smaller than the non value.

And it should look like this to return one plus the next recursive call.

So total smaller in using this num.

So once again, if the input user in this specific function goal in this specific recursive call is

less than NUM, then we know that to the final result.

This value should also these total numbers should take one plus whatever comes next.

OK, but if nothing was on the input user was not less than num, it was num and above.

Then in this case we don't want to take it into consideration because we don't want to calculate the

total numbers, which are not smaller than that in this case, to somehow to to relate and to call for

the next recursive call.

We should do like something like this return total, total smaller for NUM without adding this one to

the final result.

OK, so that's basically the whole solution that you have for this exercise.

And I know that's not the trivial way, and that's not so easy to grasp at first, but let's try to

make some example.

Let's say now equals to four and let's say we have like these numbers two, three and no, let's go

like two, five and three.

OK, and then minus one.

And what I want us to do now is to simply to run all of these function again and again.

OK, up until we see these full visualization of what is going on behind the scenes so that this way

I hope and I think it will be much easier for you to grasp is what is going on here in this function.

So let us start.

And the first thing that we have to do is like to use our drawing thing.

OK, so.

Basically, basically, what will happen in the main function is very simple, we will simply like create

a number and no equals to four and then we will create also some I don't know, total smaller numbers

will say it will be equal to the total smaller function for this given number four.

OK, so that's will that will be our first call to this function.

And what we will do is that we will write down that this is the first call in this case num equals to

four, right.

NUM equals to four.

And we come here and we ask the user, please enter a number, OK, please enter a number of ganef input

user.

So in this case, input user.

So we have these Nomikos to for the input user, in this case, the input user, let's call it like

input will be equal like we said here, will be equal to two.

So input equals to two.

And then we go through this next line.

So if input user equals to minus one, no, that's not the case.

If it's less than NUM, then this function, these function calls should return one plus the result

that should be received from the call to the total.

Smaller for this given num.

So then we will have another call.

Right.

To calculate this value that will be like with num equal to for and input equal to five in this case.

Right.

That's the next call.

So we called another call for, for this function.

Total smaller number equal to four.

We ask the user once again he answers the five.

OK, so this function, these function call also checks, this condition false checks, this condition

also false and it returns total smaller for NUM.

So it should return this result should come to here.

But what is this result?

We still don't know it.

We call another call for a function total smaller.

Right return total smaller for num.

So we know num equals two for and input here on this call will be get R.

S three so input equals to three.

And now what we will do is simply go again.

If input is equals to minus one, return zero.

That's not the case.

If input user is less than num.

OK, is this less than num.

Yes.

So this function should return to here one plus the result of the next call to total smaller and then

we call this function again total smaller from the start with once again num equals two num equals num

equals to four and we get an input again and the final input is minus one.

So input equals two in this case two minus one.

And if that's minus one, we know that if input user equals to minus one, then we return zero.

Then from this function call we return zero.

OK, that's zero and one plus zero.

That's the result.

We return also from here we return one.

So one return to here is one.

And from here we know that the results should be also one.

So that's one plus one.

And the final result that will be returned is two, which is exactly what we have expected, because

that's the total numbers smaller than four.

So which these two and three in this case.

And that's what happening behind the scene.

These are basically the recursion calls, the recursion function are recursive, for instance, that

are called one after another.

So you start with one function call, OK, from here, that's the first one you get into here and that's

the unit you specify.

You run all the commands and you want to already return one plus something, but that something is unknown.

So that's why you call this function once again.

And then that's the second instance.

And you run it once again from the start and you find the result and you know, OK, I can return it.

I can't return the total smaller that will be received from the next call.

And then you go again, again, again, until you reach some stopping condition when you don't have

to make any additional recursive calls.

In this case, you simply return zero and you build your way, let's say, down or up, however you

look at it to return your final result.

OK, so take your time, compare your result with my result and make some conclusions for that and see

if everything was working correctly in your case.

If not, also try to fix that.

Save the stopping condition is OK if the logic behind the recursive call is all right, if also there

was no endless calls and.

Yeah.

So this is for this video.

Guys, I hope you got as much information as you as you want it.

And until next time I'll see you then.

Please also leave some radio, some feedback to let me know if you like this video.

And until then, my name is Lord.

This is Alphatech.

I'll see you then.

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