Hey, guys, what's up?
So in the last we do over togged about Selection's art, in this video, we will learn what is the Mozart
algorithm?
OK.
So let's take an example.
So suppose my art is.
So might add elements are, let's say, five, four, three.
One and two.
So this is my area.
So where those come compare just.
So compare our descent.
So four will be compared with five now in the final Lizzard for sure to come before five.
OK.
And so did Eddie for sure to come before five.
Let's call it G.
And this will be Jabe, less one.
OK.
So this for sure to come before 5:00.
So what I will do, I will slap.
So this will become food.
And this will become five.
My because in the finality for sure to come before five.
Now, compare these to.
Three sure to come before five.
So slap again.
So three and five.
Now, again, compare what is sure to come before five.
So when.
Five.
Now compare again to show to come before five.
So again, look swiping.
So two and five.
So this is my new Eddie.
So for.
Three.
One.
To.
And five, so this is my new day.
Now I will do the same look compare for entry.
Today is sure to come before 4:00, so step three and four.
Now compare.
Venture to come before Ford.
So one and Ford now come bail for and to do a show to come before the Ford.
So step two and Ford.
Now compare Ford and five.
So Ford should come before five.
Do nothing.
OK.
So do nothing.
OK.
Now, our new ad is so our new ad is.
Three.
When?
To.
For.
And faith.
OK.
So compare.
Venture to come before a tree.
So slap.
Now compare.
Those sure to come before 3:00, so slap.
Now compare.
So this is correct.
OK.
Three should appear before four.
So do nothing now compare for to come before five.
So do nothing.
Now, our final today's.
So this is our new Eddie.
Van.
Two, three.
Four and five.
So does this or today.
And this is my final answer.
So what if you will follow the same approach?
Sepp.
So if you compare, compare what will happen there, a decade equation.
Do nothing.
Compare.
They are dead, correct?
We shouldn't do nothing, compare.
Do nothing.
Compare.
Do nothing.
So this is my son, Daddy.
So my question to you is, how many times do we have to.
So how many times we have to do all this?
So in this case, I was having five elements.
So if I am having five elements, how many times I have died?
So first time.
Second time.
And third time, so I did three times.
So after doing two times, I got my answer.
OK.
So if the number of elements was five after doing three times, I got my final answer.
Now.
Now, let us consider the worst case.
So what will happen in worst case?
So it will happen in worst case.
My area will be reverse this order, so reverse order means my area will be sorted in reverse order.
So four, three, two and one.
So my adays started in reverse order.
So this will be the worst case.
OK.
So this is worst case.
Now, hey, Ed, we will try to understand that for any elements.
How many times we have to do stepping so compared and to step three and four compare and swap so to
for compare and.
So when and for so first time soffer doing first time.
My new ad is.
Three.
To.
When and for.
So this is my new ETTY combat and swap -- bed and swab -- bed and do nothing.
So a second time.
Now, I might add, is.
So.
My adays to.
Then one, then three.
And then for.
So compared and slap.
So when we come here, they will come here, come back here.
Do nothing.
Compare.
Do nothing.
So third time.
So after doing two times.
So after doing two times, I got my final answer.
My edit got sorted one, two, three and four.
OK, so my add is sorted.
So this was the worst case.
And I have to do three times the number of elements are forward.
So I have to do three times.
OK.
So this wrapping things I have to do three times so we can also say like this that.
For starting in numbers.
For sorting in numbers, what to do is start and minus when numbers start and minus one numbers.
You want to sort end numbers.
I'm seeing you.
Hey buddy.
Start and minus one numbers.
So if and minus the numbers are sorted.
That means if they are at the correct position, then the last number will also be at its great position.
OK.
So that is the reason for any close forward.
I have to do this slipping two times.
Why?
Because for sorting in numbers.
If we start and minus one numbers, then the last number will automatically get its correct position.
So court is very simple.
First of all, how many times do we have to do this wrapping things?
And minus one times.
So count to close one count less than or equal to N minus or times.
We have to do this slapping thing.
And the count plus.
Plus.
OK.
Now I will start from zero.
I have to start from zero.
The slapping you can see here.
The setting was starting from zero, and this is.
Minus one.
OK, so the spangly start from zero, so this is G and this will be the final rally of G.
So jaivin go from this to this gibber hotel and minus to Vion minus two, because I'm comparing G and
G plus one, if you will take J here.
Then J plus one will become N.
And if you will write a fan, that will give you segmentation fault.
So Jay will start from zero.
Jay will go to second last position and Jay Pless place.
So what I was doing if.
F g is greater than a f j plus one.
I am comparing to our descent values, then what I will do I will scrap.
Swab of J and a of jobless when.
So this is all that we have to do.
OK?
So Vion minus two.
So if the value of JS and minus to put J and minus two.
So this really will become N minus one.
Correct.
Now put.
And J equals and minus one.
So if you put the Jan minus one.
This will literally become an because and minus one.
Plus one.
So this value will become N.
And you are doing a off in.
Virtual guru segmentation fault.
So that is the reason I will go to jail.
And minus two.
OK.
So this is all that we have to do.
So if Jay.
So this is my Jay.
And this is Jay Placemen.
So I believe what should happen.
The value at the J should be less than Value-Add Jeab less than to get the element sorted in ascending
order.
So if Jay is bigger, if Jay is bigger than SREP, then we have to swap.
OK, so let us ride the cold.
So one more thing before writing code.
Have you noticed one thing here?
So if you look carefully, the biggest way you enforced arbitration reaches its correct position.
So five is the biggest failure in the area.
And in one eye attrition, five reach its correct position in second attrition, the second largest
value, you reached its correct position.
Similarly, in the third arbitration, the third largest value guarded correct position.
And similarly, there are two.
And then when you can see here also.
So in the first iteration, the largest way Lou got it correct position in the second operation, the
second largest way, Lou, got the second largest way, Lou Waters correct position in the turnout operation,
the third largest trade Lou.
Got it.
Correct position.
OK.
So you can see.
In the first hour operation, so forced attrition, largest Relu welcome, largest relief will reach.
And in the second iteration, the second largest, Trelew, will reach at its correct position partite
duration.
The third largest, Trelew, will reach at its current position.
Okay, so my area is getting slaughtered in this way.
So this is my unsorted.
And this part is sordid, so the sorted is in this week in case of Selection's art.
So if you remember.
In the selection sort, what we did was, if you are standing here, find the smallest value in the
right hand side and put that value here.
So in forced isolation, the smallest value will reach added position in the second rotation.
The second, the smallest value will reach at its correct position interpretation.
The third smallest value will reach at its great position.
So in selections art, what is happening?
My edit is getting sorted in this way.
So it is getting started in this way and this part is unsorted.
And in case of bubble, my ED is getting sorted in this way and this part is unsorted.
So this is sort of my Eddie is my it is getting sorted in this way first and largest, you know, second
largest, then third largest.
And here first, the smallest value.
Then the second smallest value.
Then Tourism Australia, then forced military ends on.
I so let us write the code for Bubble Sword.
So the court is very simple.
How many times we have to perform this?
And minus one times.
OK.
Why?
Because we have already seen the worst case in worst case.
If the radio fan goes forward with it two times.
So we have to do.
And minus one times.
And generally start from zero.
I will start campaigning from zero.
I will come back J and J plus one since I am using the year plus one.
So the maximum end of the year will be N minus two.
OK.
That makes sense.
I love JVB and minus two because I am comparing David J plus one.
Okay, so if O.J. question my niece, do this where Luis and minus one.
So if Jay is good, then Jay Letwin, then I will lose Heping.
So they decide the gold.
So there does name this Veloz bubble sort.
So what was art and art CPB?
So let us take input from the user.
So four and I equals zero.
I let them and I bless, bless, sit in if I let us make an error.
So the size of the arrays and.
Now I will write a function bubbles out.
So bubble what Mozart will take as input.
So Bubbles Art will take two things, Eddy and the size of the eddy.
And it will start my eddy.
So my art is ordered.
Now let us print thus Outhred any sort of order intake was a zero a less than in a Lesbos sea out of
a.
OK, so let's inside the quarter for the wizard.
So this function will return void.
OK.
Because I'm just sorting that out.
I am not returning any value to mean so bubble.
Saad, it is taking two things as input first lady.
And second, the size of the Eddie.
So forward how many times and minus one times Clow count equals one count less than or equals and minus
one count plus plus.
Now, what we have to do, we have to just compare and discern numbers.
So I'm starting from zero G is less than articles two and minus two.
So this is important.
And minus two J.
Plus.
Now, what do you do, you will compare their descent to numbers.
So if A of G is greater than he of J plus one, then you have to swab.
So swab of G and A of G plus one.
So this is all that we have to do.
OK.
So I told you ARIAD passed by at events.
So if I am changing the values of Eddie here, this changes will be reflected in function men.
OK, so one more time.
I told you when you pass Eddie to a function than Eddie, I passed by reference.
So if you will do changes in the Eddie, those changes will be reflected in the main function in the
calling function.
So a number of elements out of five and the values are, let's say five, four, three, two and one.
So this is my output, which is Saajid.
Let's say member of elements are five and the elements are five, four, three, one and two.
So again, this is producing the correct output.
So let's say the number of elements are forward and the elements are at the door during be 10 and 50,
so elements are getting started.
So this is how bubbles art works.
Okay, so now let us discuss one last thing.
So how many steps?
But Mozart takes two is ordinary.
So this outer function is earning approximately and minus one times.
So outer loop is earning and minus one times and inner loop is also running.
And minus two times.
So a number of steps, number of steps equals and minus one and two and minus two.
OK.
So these are the number of steps.
So if you will multiply them, we will get and squared them, then anthem and then some constant.
OK.
So let's put an inquest into the power six.
So this really will be ten to the power to this value will return to the power six.
And this is something constant.
Now tell me in front of this doesn't have any significance.
No.
And friend often of the power will well but the power of six is nothing.
OK.
So I can say the number of steps is a close to end squared.
OK, so the number of steps is actually called time complexity.
Time, complexity and complexity means how many number of steps your program took to execute.
OK.
So this thing is clear.
So how we report them?
Complexity.
We will write big or record and square.
So this is called time, complexity of bubble sort.
So this is the time, complexity of bubbles.
So what was the time?
Complexity of selection's art.
So time, complexity of Selection's art was also in the square.
Okay, so selection's our time.
Complexity was also in the square.
And the time complexity of bubble sort is also and square.
Now, any idea why we calculate time, complexity?
So.
Suppose you want to buy Ocado.
So what do you will check?
It will check.
What is the mileage?
What is the cost?
How many number of seats?
What is average speed?
And there are many factor.
OK.
So for deciding which car to buy, you will see many factors.
OK.
So there are many starting.
And what items?
There are many sorting algorithms.
How we will decide which sorting algorithm is best.
So what we will do.
We will find how much time is my program taking to execute the algorithm which take the least amount
of time.
The algorithm, which takes the least amount of time, is the best algorithm.
OK.
So that is the reason we calculate, Pam, complexity of the program to compare to algorithms or to
compare two programs.
So both levels, art and selections.
Art both Pam complexity is N Square.
They both take and square number of steps to execute.
OK, so Julia, time complexity is a very big topic.
I have just given you an introduction to complexity.
That is why we calculate time complexity.
OK.
So this was just an introduction to time.
Complexity and complexity is a big topic.
OK.
So this is it for this we do.
If you have any doubt in bubbles, Art, you can ask me.
Thank you.