Hey, guys, what's up?
So in the last video, we talked about bubbles and.
And I told you that bubbles are take's and square number of steps to sort out Eddie.
OK.
So, for example, if my input is, let's say three, four, seven, one, 10.
So if my input is this, how many number of steps it will take.
It will take and square a number of steps.
OK.
So if my error is one, three, four, seven and 10.
So if my input is this, then also it will take into a number of steps.
OK.
So this Eddie.
This error is unsorted, Eddy.
And this ad is unsorted.
Then it is taking and screen a number of steps.
This area is already started.
This area is already sorted.
Then also it is taking and square a number of steps to sort this area, which is already sorted.
OK.
So if I give this as input, my Bosshard will take and growing number of steps.
If I give this as input, then also those are the sticking into a number of steps.
So our aim is to optimize.
Our aim is to optimize bubbles out.
So that if the import is unsorted, it can take and a number of steps.
But if the FDA is already sorted, it will take and steps.
OK.
So we want to achieve this.
So what we want.
We want to optimize our bubbles out so that if the given Eddie is already sorted, then it should pick
and the steps.
So how we can optimize our blizzard.
So let's take an example.
Let us try to understand with the help of an example.
So suppose the given area is two, four, seven, eight, nine and 10.
So the given area is already started.
OK.
This given area is already sorted.
And let us implement bubbles out on it.
So.
Compared no slapping.
Most.
Compared.
No slap.
Compare no slap.
Compare notes app.
Compare no Sepp.
That means if the given area is already sorted, then no swapping will take place.
OK, so tapping will not be there.
Swapping will not be there.
OK, so we can use this property.
OK, we will use it.
We will use it that if the given array is already sorted, if the given Arizona sorted, then swapping
will not be there.
We will use this so that our sorted so that if they in part is already sorted, then bubble start big
and steps.
OK.
So how we will do it?
So let's see.
So let's name this violence optimized verbal.
Optimized mobile, mobile, art, Nazi P.P..
So what I will do.
So this was our all of it was hard.
So we will keep it.
And Pastor Ted.
So what optimization we have to do?
So this slapping, we have to optimize this.
So what I will do?
Let us take a variable and flag.
So I'm taking a variable and flag, which is initially zero.
OK.
So I am taking our flag variable, which is initially zero.
Now I will enter this loop.
OK.
So in this loop, so if there's swiping what I will do, I will change the value of a flag to one.
OK, so that means if the input is unsorted, this condition will be true at least once, this condition
will be true.
And and these two lines will be executed.
So when this for loop end, I will check the value of flag.
So if flag is still zero, if flag is still zero.
That means the arrays already started.
So what you can do is break.
So these two lanes, initially, my flag goes to zero.
So if there is Sautter, this condition will always be false.
OK.
If that is a starter, this condition will always be false.
Hence, these two lines will never be executed.
And this for look will terminate.
Then I am checking if the value of flag is still zero.
That means you can right here.
That means my error is error is already sorted.
So what you should do is come out of the loop.
OK.
So come out.
Come out of the loop.
OK.
So what this big showdown will do.
So this brave statement will break this outlook.
OK.
So this was closing and this was opening.
So this big statement will break this loop.
I will come out of this loop.
And this is where my function end.
OK.
So this is all that we have to do.
Now, this is called Optimized Mobile SART.
OK.
It will take and the steps, vital big steps.
So my flag is zero.
So let's say that elements are one, two and three.
So I will check GMG.
Listen, compare.
No slapping.
Compare.
No slapping.
So I will reach at this lame flag is still zero.
So flag is still zero.
Break.
Come out of this loop.
So how many number of steps it took?
As May a number of times as this loop is running, so this loop is running and times.
OK.
It is actually raining and minus two times or minus one times, but it doesn't matter.
OK.
These questions, one, two, three.
There doesn't matter.
We always report our answer in terms of.
And so this loop is earning end times.
So this optimised verbal sort will take and steps.
If that is already sorted.
OK.
So the main logic was just to use a variable flag.
If there's a stepping, that means that is unsorted.
Let me say, there is unsorted and the value of flag will change, the value of flag will become one.
And this condition will become false.
So Blake will not be executed.
OK, so this was the whole logic.
OK.
So if you have any doubt regarding the optimized bubble sort or regarding the Mozart art, you can ask
me, OK.
Feel free to ask.
So this isn't for this video.
Thank you.