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

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 where should we start?

OK?

First of all, whenever you get a question in recursion, then what I suggest is, first of all, to

create the signature of the function.

OK, so the signature of the function is going to be the function is going to be of a void type.

Since these function, we do not expect it to return anything, and these functions should only print

some values that a screen, then probably the type of the function should be void.

You agree.

All right.

So let's call this function.

I don't know.

Special sequence print.

Special sequence print.

OK, I don't know exactly what name we should name it, but let's go it with this way.

And as we were requested, the function should receive three integers.

The first one should be total.

We should specify the total length of the sequence of once and twos that are this function is expected

to print.

Then what we are expected to receive is number one.

And finally, int number two, right?

Awesome.

So the first part is complete, we've created the signature for these function.

Now what we want to do is very, very simple.

OK, we want to start thinking about how should we approach it?

So we remember that the previous examples, let's copy these examples right here so that we will have

them.

So for example, if we get a total of three, number one equals two to numb, two equals two four and

then we print this sequence.

So the first thing that comes to mind is let's use some.

We're a loop or while loop.

And that's it.

Right?

Print run this loop over the length of the total print number one.

Then again and again, OK, in some iterations, then to run another loop and to print a sequence of

number two is of this length.

OK, so.

This could be very easy solution to solve this exercise, but this would be not the actual thing that

we were requested.

This would be the iterative approach of using iterations, using for loops, while loops and so on.

We were requested to develop and design a function that should be a recursive function.

OK?

Using the recursion concept.

So that's not how we are going to do it.

We are going, OK.

I'm suggesting this approach, OK.

I'm not sure that it's the best approach, but sometimes also it may be very useful.

OK, I'm going to show you so you will decide for yourself which approach you prefer using, basically.

First of all, understanding the the fullest, what you should do or better say just based on your previous

experience.

Just throw things in the function and try to figure out how it will react and make adjustment to make

it be the exact solution that you want.

OK, so we know that probably OK, we will need to print the value of no one.

And we will also need to print the value of number two.

And probably we should make the recursive call again and again and again until want until we reach total

value that will be of size one, for example, or less, let's say less than one.

OK.

So what we would like to say is that let's run this function.

OK, let's make the print operations.

Let's make the printing functionalities.

Let's make print half and use here.

Let's use higher percentage and then print half number one.

Then let's use print f percentage.

Let's print number two.

Then let's use the recursive function call and let's call it special sequence, print and print.

What?

Total minus one.

As well as no one.

In them to.

All right.

So that's basically what we are going to do.

We are going to use the special sequence print and let's see and try to figure out what it will do,

OK, so we know that first of all, we will need to print them one.

We will also need to print them two.

And we would like to call this function.

Again and again and again.

So what will happen now?

Let's say the total was three.

No one was still and number two was four.

So we printed out two, then we printed out four.

OK, and then we call this function with the value of two and again and again, then probably this function

is going first of all to be want an infinite regulation because there is no stopping condition.

We will call this recursive call again and again and again until the resources of the computer are over.

OK.

So what we would like to do is to say the following let's say if total is greater or equal to one,

then in this case only in this case we will execute this program, right?

So we will say that as long as we did not use the printing operation like it was three and we didn't

use it three times.

So every time that we will call these functions, we will use total minus one.

So once we will run it for a total equal to three, then four two, then four one, and then we will

not run this program again.

Okay, this function will be over because the condition will not be true.

So this way we assured that we printed out a sequence or, let's say, not a sequence.

We made sure that we printed out number one three times through the screen and also number two three

times to the screen.

So if we run this program right now, let's say special special sequence print and we will use total

equal to three number one equals to two and two equals to four.

And we run this program.

Then what we expect to see?

OK, let's hope that it will work.

Then what we will see two four two four two four.

OK, so first of all, we know that no one was printed three times in NAM two was also printed three

times, but that's not exactly what we are looking for.

We are looking to make this sequence of, first of all, printing out the tools and then printing out

the force.

OK, printing out, first of all, number one and then printing out number two, total times.

So if we change the order between these two printouts and we use it like this.

Then probably the result is going to be pretty much the same, just instead of using two for two four,

we will see for a two, for a two, for a two.

It's also not what we are looking for.

So let's try to come up with a good idea and a good solution to this one.

So let's say that we will try to figure out what should happen.

Whenever we try to print it out so we cannot print number one and number two, one after the other before

we make the recursive call.

What we would like to do is to split out, split out the middle, the exact middle of the result, so

that this way we will print out three times or total times, number one.

OK, so number one, printing.

And then we will print number two printing.

And the way to do that is very, very interesting.

We will say that here we will make the recursive call and reduce number one every time until we reach

the time that we printed out total times.

And then when we build our way back in the recursion, OK, we called one instance and then the other

Winstons.

But each of these instances, they printed out the value of number one.

Then they called their recursive call.

But when the recursive call that the called is over, they still will have some commands to complete

in.

These commands should be referred to the printing of number two.

OK, does it make any sense?

Let me show you how it will look like in our code.

So we will place print f percentage number one, then what we would like to do is to call to make the

function call.

And finally, we would like to print number two.

So do you feel me?

Let's say that we have these function.

Right now, OK, we will use F for simplicity with three and two and four.

These function what he does.

OK, let's say that this is the console that we print.

What these function does, it reaches these line prints the result to the screen prints number one.

So it prints two, then these function calls special sequence print, right?

Then it costs special sequence print f for a two, two and four.

These function, these instances, all it does is once again printing out no one, so we print to these

function.

All it does is also calling them special sequence.

Print for now equals to one so f for one, two and four.

So these function, what he does is printing out number one to the screen again, and then we call this

function once again for four want four, f zero, two and four.

Now in this instance, we ask this question if Toto is greater or equal to one.

The answer is no.

So the instances over this condition, the the lines of code related with this condition are not executed

inside of this instance.

Then the instance is over because we executed all the lines of code of these function.

So we say this function is over.

Where did we stop?

OK?

Where did we stop?

We stopped right here, right inside of special sequence print, when total equals to one on one equals

two, two and no two equals two four.

So we stopped a baseline inside of this instance.

All that remains right once we are executed this function, because here it is, it's over.

All that remains now is to print number two.

So we print four.

That's it.

This is done.

And this function is complete.

Who called these fonctionne who called this instance, who called it.

The special sequence print, when Total was equal, Stewart well was equal to two, no one equal to

42 in number two equals to four.

So these function that called these function, that's now they say instance, this now is over.

All that remains for it to do is to use the print percentage, the number two.

So we print four.

And the same we do also four here and we print four.

And this function is over and this line is over and we are ready to move on after we have printed out

this sequence of.

Now, once now, one values off length, total and then number two values of length total.

So I hope this explanation is clear to you guys.

Very, very important to understand it and basically to know how it can be done and how it can be used.

There are a.

A lot of variations that I can basically everybody can make out of this exercise.

OK, maybe some of them.

I will also add additional videos.

OK, and I will not make so dedicated and descriptive explanation of the solution, but I will just

show you the resemblance to this exercise and how basically you should treat exercises of these kind.

So I hope you liked this video.

I hope you like the explanation and the result.

Make sure you understand it.

Try to write it again on your own.

It's not very complicated.

It's not very difficult, but it still requires some attention in some practice.

OK.

Don't go about it and say, OK, I understand everything you said and there is no problem about it.

I will know.

Let's say in the exam or on my job interview, I will know how to do it.

I do not recommend such approach.

What I do recommend is basically closing this solution, trying to solve the exercise on your own,

making sure that it works for various options or, for example, making sure that it will work also

for at least one.

The second example that we had, let's try to run it.

And then when you see that it works at least for three, four or five examples, then compare with the

results I show.

And that's it.

OK, so thank you guys for watching.

Keep on practicing.

Keep on moving forward.

My name is Vlad.

This is alpha tech in until the next time.

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.