All language subtitles for 6. A Program to find if an Array is sorted - 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
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

OK, so now let's start solving this exercise.

OK, so basically we will assume that it's used here.

Fine.

I don't know.

Sighs Fight.

OK, and let's create an array of this size.

So age, IRR of size, size.

OK, now we are going also to use this variable that will be used to get inputs from the user into iterate

over all the elements of this array.

So Fawry equals zero iis less than size plus.

And as long as this condition, as long as it is less than size is true.

It is, yes.

Then in this case we are going to print a nice message that is green.

Please answer now.

Element number percentage D and we are going to read this value and to storeyed where are we going to

store it inside of the associated element in these arrays.

Historic inside Iraq index.

OK, is that clear so far?

So that's the operation of just reading the inputs from the user.

So that's related to reading.

Reading includes inputs of reading the values of the elements from the user.

OK, awesome.

Now once you have your array ready on, basically you entered, you got all the elements from the user.

Now it's time to see if the arrays really sorted from the left or the right, sorted or basically not

sorted at all.

What do we have to do here?

What do you think should be what techniques should be applied?

OK, so what do you think, guys?

We have three options, three options here.

So one of these options has finally to be printed out.

So let's say if I don't know, we found out something, then I don't know.

Print half of the array is like really, really sorted.

OK, so that's option number one.

On the other hand, there may be also another option and another option also with some conditions.

Right.

So if and if and if and so on.

OK, so the array is sorted and also the array is not sorted.

OK, so three options.

What do you think?

How should you approach this exercise, how you basically should think about it, how should you solve

it, how should you even find or what is the expected result.

OK, so.

Any ideas and one of the options that you have to understand is that basically what you will have to

do is at least look for are a couple, at least one pair.

OK, one pair.

That does not satisfy the condition here.

So first of all, the condition here, what is the condition is are left element.

All the left elements are less then the right elements.

OK, for any pair that we take Fasal, for any pair, for any pair, the element on the left should

be less than the element on the right.

So that's how it is.

OK, so for any pair that we take in this sequence of elements, all every element on the left should

be less than the element on the right and in this condition is not satisfied that for sure we can see

that the array is not OK.

So if we take also this information for a like this array, OK for the secondary.

So for any pair, the left element should be less than or at least equal to the right element in this

condition.

He's not satisfied, at least for one pair.

Then we can definitely see that the array is not sorted at all.

So let's start and see what we can do with that.

So for I equals to zero as long as I is less than size.

I plus, plus.

OK, so now let's do it like this.

So what should we do, what should we do?

So let's first of all, construct the conditions.

So if they are at index, I have the left index.

What should be the left index here, i.e. minus one is less than a right index.

I OK, if that's the case then maybe we can conclude something.

But the problem here is basically should we start on the index from equals to zero, should we do it.

Because in this case there will be a problem because we will try to access ARRL index minus one.

So I will start from I equals to one.

OK, awesome.

So if there are at index minus one is less than this one, then no problem.

Nothing can be concluded out of it.

Right.

But let's say that also we have like this condition for the really sorted and also we have like this

condition for the source of the rain, but they do not pretty much give you anything.

OK, we have to make some assumptions for at least one pair that does not satisfy these conditions.

And what do I mean by that?

Let's simply start with this one.

OK, so let's start with this one.

So if you are on the left is not less than or.

Or are equals to the element on the ride then in this case?

OK, in this case, but in this case we can ride down like this.

So the element on the left is greater than the element on the ride.

So element on the left is greater than the element of the ride.

OK, so that means that neither of these conditions or this one is satisfied and that means that.

Basically, the array is not sorted at all.

OK, we can also create some fled.

OK, let's say flag and we will use this flag as something like this.

So flag equals to two.

And if flag equals to two, then two means to means that it's like really sorted.

That's just our conventions.

One will mean that the array is sorted and zero will mean that the array is not sorted at all.

OK, just some flag for our.

Of course there are additional options to solve this exercise, but I'm going with this one.

So if you are on the left is greater than B.C., are that then the value on its right.

So then definitely we can say the following thing.

We can say that.

The flag should be equal to zero as well as we can, also can't break out of this loop not to execute

any anything else, because that's does not make any sense.

OK, all right.

So if that's the condition for r for what?

For the not sorted.

OK, so there you go.

You've basically found out that it's not sorted.

You just found at least one pair that does not satisfy neither of these conditions or this then in this

case, put the flag to be zero and break out of this loop and go basically here and printed that the

arrays not sorted at all.

OK, so that's something we took care of.

Now we have to like to understand how can we make the distinguish distinction between the sorted and

the really sorted?

OK, so for that we will use another condition.

And we will say that if the element on the left equals to the element on the right, OK, meaning it

does not satisfy the condition of the really sort because there is at least one pair that is not OK,

that is not are basically satisfies the condition that the element on the left has to be less than the

element on the right.

OK, then in this case we can definitely say that flag will be equal to one.

OK, so that's basically associated with the sorted.

OK, but not really.

Sort of not really sorted.

OK, is that clear.

And if that's the case, should we also use the break.

Well what do you think?

Absolutely not, because there may come also another pair that this condition will be satisfied for

it.

OK, but this condition basically said to us that our first assumption, OK, and our base base case

assumption that we will assume that the array is really sorted.

And if we will find out at least one OK, at least one pair, that does not satisfy the condition that

any element on the left is less than the element on the right, then basically if we found out like

this, so the element on the left equals to the element on the right, then in this case we can assume

that the array may also still be sorted.

OK, but not really sorted.

And if we found out that there is at least one pair that satisfy this conviction that the element on

the left is greater than the element on there, right.

Then basically we can say for sure that the array is not sorted and it doesn't matter what elements

will come next.

So that's the loop of the body that we have here.

I hope nothing.

I didn't miss anything.

And now we will simply again conclude this exercise by just updating.

These are flags.

And this can be done in the following way, so if Fleg equals equals two, one, two, two.

OK, so the array is really sorted.

The flag remained the same.

And if flag equals to one, then we can say that the rate is sorted but not really sorted.

And if flag equals to zero, then in this case the array is not sorted at all.

OK, so we can also use here LC.

Right.

And also Elzy also.

So let's just executed and see if it basically works as expected and we can get all the information.

So let's go.

Where is our example.

So one, two, five, seven in 10.

I'm just executing this example one.

So the array is really sorted.

Congratulations.

Awesome.

So the first example seems to work as expected.

Let's just now try the second example.

It goes like this.

So one, two, two, five and 10.

And they should printers that the the array is sorted, but not really sort of the array sorted because

we have a pair here of two numbers that the right or the next number is not greater than the previous

one.

So the array is sorted.

And finally, for our third example here, come here, come here, come here.

OK, you're here.

OK.

So for our final example, we will use like one, two, five, three and ten.

And what do you expect to see here?

Basically, you expect to see here one thing, a message of not sort of printed through the screen.

And why is that?

That's because we have a pair, at least one pair.

OK, there maybe also more pairs that satisfy this condition, but at least one pair.

So that says that the previous number or the number on the left or the previous number is greater than

the next value.

OK, so five is greater than three.

So it kind of stops the increasing between every pair of the numbers.

OK, so two to five is OK, five to three and that's a decrease.

And that's why I think there should be a message of the array is not sorted.

So they hope this explanation is clear to you guys, OK, that's just the simple program that we've

written together with a few examples that we've seen right here.

And there is basically some logic.

There is also there are also other solutions to solve it.

OK, I guess maybe some of them are.

Oh, sure there are.

Some of them are longer.

OK, but that's just the trivial solution that I prefer to be using for these basic scenarios.

So three options.

So I was just and I make some assumptions that if flag equals to two, it will be really sorted, one

sorted and not sorted at all.

And I simply iterate over all the elements of this array every time taking a pair of elements and element

on the left and then the element on the right and basically asking some conditions to like to do ask

at least and to find to try finding at least one pair that does not satisfy a condition for a given

status, for a given flag.

And based on this result, to make some assumptions whether I should change the flag to zero or two

one.

And you can see also that the flag cannot be returned to be equal to your flag equals to two, because

there was at least something, some period that changed the flag from flag equal to two.

And yeah.

So thank you guys for watching.

My name is Vlad.

This is Alphatech.

I hope you are doing great tonight on your own.

Give me some feedback, some reviews, some comments, if you like the video and if you have any questions

and until the next time we the exercises together, I wish you a great time.

Productive learning, you know.

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.