Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
OK, so now let's try to solve this exercise together, shall we?
And the first thing that I want to talk with you guys about is our first and basic usage of using the
for loops or while loops to iterate over each of the elements of this number and finding out the solution.
So basically, just talk about the logic of the iterative approach.
Okay, and then we will come in, try to think about the recursive one.
So the whole idea here is every time to take two values, OK, every time to take on each number to
take the right, most digit in one digit on its left and compare between them.
And based on these comparisons, we will make assumptions whether these two numbers are very descending,
very ascending or neither of them.
And based on how we move on, we will say that, OK, we have a flag that specifies that we found out
a pair that is very ascending.
That means that the next pair should also be very ascending.
If not, that means that the next pair.
Indicates the status that the whole number is neither very ascending nor very descending.
So with four loops, it's pretty much something that we can work out, right?
You can also try to solve it on your own using sound for a loop.
But we are talking about a recursion in our goal.
OK?
Our goal is to split this exercise in into some sub problems.
OK, so our main problem is to find out whether this number, let's say one to four, is very ascending,
very descending or neither of them.
In one conclusion that we can make is basically that here we will take this status between these two
numbers.
OK, so we will say that we will say that 10s will be equal to two and a units.
Will be equal to four.
Okay, so we will say tannen's equals to two units, equals two four, and then we will ask a simple
question.
We will say, let's basically we found out the problem about it.
Let's split it into smaller problem and talk about one and two.
If we come to think about it, then tense here equals to one and then units here equals to what to do.
So we know that basically from here.
It probably also be our stopping condition, OK, whenever we have a number of at least two digits.
OK, one digit or digit.
So we ask a simple question if Thames is less than units, then we can assume that this number right
is very ascending, very ascending.
Do you agree?
And then we'll try to return the result that this number is very ascending and it can be indicated by
returning one.
Right.
So now what we have to do here is to ask a simple question if the and the units in these numbers, if
they represent a very ascending.
Or are there?
OK?
And also so far, we returned and received from the sub problems we received that there was a result
of various sending.
Then also these functions should return one, but only when the condition for both of them applies.
OK, so let me draw once again.
OK.
We specify we use some time to to draw these exercises exactly before we start writing the code if you
are interested in the code, so we can skip up to this part.
But for now, we are going to solve this exercise.
Also for, let's say, the second example.
So we start with what with nine, six, four and three.
We say that the units equals two three and we say that the town's equals two four.
Then we make the function call for the next one, four, nine, six and four, divided by 10.
All right, that's what we do.
Units will be equal to four and 10s will be equal to six.
Then we make another function call for a 96 because we cannot say for sure if this number is very ascending
or very descending just based on the units and the tense.
And inside of these function, basically when we have two digits, we can say that units equals to six
and 10s equals to nine.
That means that tenths from the left is greater than units on their right.
That means that we are going to return from this function, that this function is what is very ascending,
that this number is very ascending.
OK, so we return minus one.
And then right before this function is going to return something, we ask a simple question.
We ask if.
The return value for the SA problem was minus one, meaning it was very descending this pair of numbers.
So we want to ask if this number.
Is greater also than this one.
Meaning if it's also very descending based on the units and the tents, and if both of these conditions
apply, then we return minus one to here.
And we do the same process here we ask return value.
So far, four nine six four is very descending.
And also four and three is very descending, then return minus one to indicate that the whole number
was very descending.
And if, for example, units here was like, I don't know.
Seven.
Then the condition of Thames greater than the units will not apply, and the result so far is very descending.
So basically, these two conditions would not work and the final result should be zero.
OK, because it was not very descending nor very ascending.
OK, so that's about the drawing that we had to make and the explanation of recursion.
OK, some exercises require from us more attention.
Now what we want to do is to start writing the actual code.
So what should be the type of the function?
Basically, we say that the function is returning zero, one or minus one.
So it's probably going to be of an integer type.
Right after that, what we do is we say what will be the functioning.
So make sure you choose the proper function name and don't use something like that.
OK.
Here's something very nice digits sorted, for example.
OK.
This function will receive No.
And what this function is going to do, this function is going to do something very interesting.
It's going first of all for every function call like you can see right here, for every function call,
we are going to extract the unique digits and the translated.
OK, we assume that the number is going to be, of course, greater than 10.
OK, that was our assumption.
If you don't remember, check out the exercise.
Okay, so you can see that here we have.
I can't open it.
So the assumption was that initial number will be at least of two digits.
So we extracted the units.
So we say units equals two number modulo 10.
Remember how you extract the units the right most digit?
Then we say intense equals two what two nouns divided by 10.
And all of that divided modular.
10.
OK, so we extract the dance off a certain number.
As I do that, I would like us to create additional variable that will hold the status that will be
returned from every function call and we will call it, I don't know and sorted so far.
OK, sorted so far.
And this variable should hold either zero, one or minus one.
OK.
So how it will look like.
First of all, we need in our recursion to use some stopping condition, some base condition, OK,
some base case and the base case can be when NAM has less than three digits, meaning two digits or
less.
And we can indicate that is the case if numb is less than 100, for example, right?
And if that's the case, if numb is less than 100, then what we can do is ask the following question
we can ask if the two digits, tens and units are sorted in ascending order.
So we ask if Tannen's is greater than units.
OK, we'll look at from left to right.
Then we say that it is descending.
It is ascending.
Sorry about that.
So in this case, what the function should do?
We know that if the number is very ascending, then we should return.
One else, we should return zero.
OK, so this LS basically refers to when units is less than 10s since we're assuming that all digits
are different.
OK?
In our NUM, that was also an assumption.
If not, we should also take some consideration with additional eve to check if they are both equal
to one another.
OK, but for now, this will be sufficient so that the base case, if we reach the number of digits,
then we can ask if the tenth is greater than the units return one, otherwise return minus one minus
one.
Sorry about that.
Yes, minus one, because this indicates that the number is very descending.
And that's it.
That's that was the whole point.
Once again, if you want also to take into account that it may be the quality numbers like twenty to
thirty three and so on.
And based on that, to say that the number is not very ascending, nor it is very descending.
So adding just additional condition, additional Ilse elseif and return zero.
OK, nothing complicated.
Then after that, we say OK, if the result, if the NUM was not basically related to the base condition,
then we will say that the results so far.
Let's sort it so far, thought that so far will be equal to what through the result that will be returned
by the recursive call of numb divided by 10.
That's what we've done here.
Every time we divided the number by 10 and based on the smaller, smaller, smaller results, we tried
to build our way up.
OK, so sorted so far equals the digits sorted, numb, divided by 10.
And we ask if so far the digits were sorted in ascending order.
That's what we would like to ask and the current write.
Most digits also satisfy the condition.
Then we will return one.
So what if we do we ask if sorted so far equals to one that means what did it mean?
That means that all of the sequence of the digits was so far.
Various ending, and we say that if tens is less, then raped less or greater, if Thames is less.
Then units right here, I think I made a mistake, right?
If dance is less than units, then yeah, that's how should be.
So if is less than units, then return one else, return minus one.
OK, because we look from left to right.
So if I thought that so far equals to one in towns is less than units, then in this case we know that
so far we've found out that the result, the digits so far were sort in a very ascending order.
And also the rightmost digit is less than one when it's left, meaning it still keeps the very ascending
order there.
Still return one.
Awesome.
And if sorted so far, equals to minus one, meaning it was very descending and the 10s is greater than
the units in this case than a return minus one.
Right.
Otherwise, if so far, the digits were not sorted.
Neither are sending or nor descending, meaning the sort that so far was zero or basically one of these
conditions did not apply with the conjunction of either of the status so far.
Then in this case, we should return.
Zero.
OK.
And that's basically it for this function.
It's all it has to do.
Now, let's take a look.
Once again, and this example and another drawing and see how it a function calls were made and basically
what these two were inside of it.
OK, so we start with this simple option we start with now equals two nine six four three.
That's where we start.
We say that the unions equals two three, and we say that the ten sequels to four and then we ask a
simple question if Nnam is less than 100.
No, so sort that so far equals the digits sorted.
So we stop here inside of this instance of the function on the value of sorted.
So far that we don't know about it, right?
We know that it should be filled by the results returned from the recursive call.
So we do not proceed inside of these incidents.
We call these function four nine six four using it stands.
Then we call another function that also waits for sorted.
So far.
It also waits for the result.
Right?
And the result should be returned from here.
So for 96, this condition is true if tens is less than units, no health.
When units, it's less than dense return minus one.
So the result here is going to be returned is minus one.
OK, so minus one will be returned to here minus one.
And where did we stop in this instance of this function?
We stopped in this line.
So inside of these functions throughout that so far, we'll be equal to minus one.
And all that remains for us to complete is the following things you've sorted so far equals to one.
No, that's not the case.
You thought that's a one equals so far equals two minus one.
That's the case.
And the tents and the units inside of these function call 10s is greater than the units.
That's the case.
Then these function, these instance should return minus one.
So minus one should be returned right here, right minus what happened minus one.
And where did we stop inside of this instance of the function?
We stopped right here.
OK.
So this line is completed, and we ask the following question No, that does not happen.
If sorted so far equals two minus one.
Then also, if we have tenths greater, then the units, that's the case.
We return minus one.
So this function finally returns minus one, and that's basically how it works.
So a function call of, let's say, inside of the main you have like, I don't know int result.
Inside of the main or some other function that called it, and in result, it's destroyed right here,
OK?
It will be better.
OK, so you have something like end result.
Equals two digits.
Digits sorted.
Four.
What was it?
Nine, six, four three.
So the final result that this function is going to return is minus one and it's going to replace these
burnt.
OK.
So I hope that's clear and you understand what's happening.
And basically, you see the whole picture of the recursive calls.
Also, what I do recommend, you guys, is take a couple of moments, try to draw all the recursive
calls that will happen inside whenever you will try to call this number one two three four zero and
see basically how the returned results will be zero and how basically this chain will return finally
zero to whoever called this function.
OK, very important.
Take these drawing lesson and draw the actual function calls, right?
The main function?
Make some.
Function calls check if the results are exactly as you expected and compare it with your results, suggest
any suggestions and yeah, make sure that it works.
Who once again, thank you guys for watching.
Keep on practicing.
Keep on moving forward.
This is very important concept, very important exercises.
I think you're getting more confident about it now.
If not, you have plenty of other exercises.
Hopefully, you will have time and arm and strength to solve them.
So until next time, my name is Vlad.
This is alpha tech.
We are getting better in programming and I will see you in the next videos until the next time.
What do we say?
Bye bye.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.