Hi, everyone.
So in the last videos, we discussed how we can use our own to make some priority.
Now in this video.
We will discuss how we can use our inbuilt minimum priority queue.
So we will start using our built Menom prior to.
Q So let's directly jump into court and let's see this index for creating our inbuilt minimum priority.
Q So if I remember this is our old code, so this is actually maximum and if you in the output, if
you will run this program, then what will be our output.
So you can see the size of six and the topmost elements from six to seven.
And then when we are getting each element one at a time, so the output is going to be in descending
order first, the largest element will come, then the smaller one, then the smaller, smaller, smaller
and the smallest.
So our output is coming out and decreasing order because we are using maximum.
Now let's see how we can create our minimum.
So let's change its name to be good to.
So now let's see this index, Susan, index is quite similar.
So proud of you, I want to create a priority queue of integers, so integers, then you have to write.
Retrophin digits, and then you have to rate greater.
Indigence and.
This is your beginning.
So this is this index for creating minimum I know this index of minimum prior to kill is really weird,
but we will not go into much detail.
So we will just we will just remember this line that we have to use.
We have to write the digits and then we have great, great advantages.
So I will provide you note that what is the meaning of character?
So this is the way for creating minimum.
Now the name is Piku and I change its name to Picado, so I am pushing in priority queue.
So the size is still six, but the topmost element is the smallest element and the smallest element
is now one.
So will come out first and I am wiping out the elements from the minimum priority queue Bittu.
So this time our elements will come out and sorted.
Amended, correct.
So now let's try to test our called.
So you can see this is the size is going to be some other topmost element is the smallest element and
other elements are coming out and sorted because we are using minimum.
So the minimum element will come out first, then the next element will come out first.
And in this way, at the last, we have the largest element.
So now we know how to create minimum.
So let's just solve one more question.
So if you remember the last question, so our last question was to find the smallest element.
So the last question we did was to find the smallest element.
Now, can we use minimum priority queue to find out the smallest elements?
So what I will do, the logic is very simple.
I will push every element inside the minimum priority queue.
So these are my total elements.
So create a minimum priority queue.
And push every single element inside your priority queue, so five, then six, then nine, then 12,
then three, then 13 and then to.
What do I want, I want the smallest elements.
So what I will do, I will call pop function.
Three times.
Basically, top and bottom, top end pub function combination, so find out the top most elements of
the topmost element is to sort of come out first and then pop the element of pop to then.
So I have to call three times now, the second time, Bob, the smallest element.
So three will come out first.
And Bob.
So he's getting Bob now.
I will pop out five because five with the smallest element and five will be here.
And then I have to do three times.
So I will stop.
And this is my game.
Smallest element.
Now if you will use medium priority queue, then your time complexities, same as and Logan just like
this one, because ultimately what you are doing the size of your minimum priority is going to be when
at first you have to insert any elements.
So for inserting an elements, the time complexity will become analogue and then you will run the loop
times.
Basically you will call the append function.
So this will become Kellogg.
And so this will be the time complexity, if you will, use the minimum priority for solving this question.
So let's take one more example.
So what I'm saying is.
So let's take this one example, it five 12, 10 zero one six nine, and the value of it is actually
for.
So that you can understand how we can use minimum priority code was all above question.
So my Ed is very simple.
This is eight, then five then.
Well, then let's say 10, then let's say zero.
Then let's say one.
Then let's say six and nine.
And what is the value of K?
So the value of Gaisford.
Correct.
Now this is already.
So what I will do, I will iterate over this.
This is my minimum priority queue.
I will agree or disagree and I will push every element inside my priority queue.
Correct.
So all these elements will be pushed inside my priority.
So let's change the name.
So this is my priority.
You correct.
Now, what I will do, I will.
Run the loop four times and I will call the function top and then I will call the function pop.
So this is priority queue, so the minimum element will come out first.
So zero is the minimum element.
So top pop zero.
Now, when is the minimum element?
Pop and pop?
What is the minimum now, five, stop and pop, what is the minimum element now?
I think it is six sort of benchtop and now I will stop.
So this is my answer.
Zero one five six.
Correct, so I can use medium priority queue and the complexities of first, we have to insert all the
elements into the priority queue.
So time, complexity, there are an element.
So when loop so and login and then we have to pop out key elements so key and the to produce login so
caillaux and login plus login.
Correct.
And the space is going to be big off and because the protocol will contain N elements.
So obviously the maximum practical approach for solving this question was the best approach.
And this approach is not even better than discarding one, so starting approach was better than this
one, starting was better.
So but we are not discussing about time, complexity, and we are just trying to use in particular,
we're just trying to learn how we can use inbuilt protection.
So let's write the code.
So this was the call for the smallest element.
Now, what I want to do, I will create a minimum priority.
So let's just come in and out everything.
OK, so let's get one more function.
So wait, so let's namer to.
So guess my list again, it will take it is and but it will take the size and it will take a very bulky.
Then they have to do so, we have to create a minimum priority, given the syntax, basically you have
to remember this index.
So proud of indigence, then you have to read.
Vector of integers, then you have to rate greater of integers and please, there's no need to go in
detail, you just remember that this is how we create I impractical.
So this is a minimum heap, correct.
Now, the approach is very simple.
Push every element inside your main priority queue.
So I equals zero.
Equals zero, i.e. less than a plus plus they're going to push every single element, every single element
into my priority given to Alfy, I am pushing every element and then I will pop out key elements.
So pop key elements and these key elements.
Will be the smallest elements because this is minimum hip.
So I have to run the loop times, so.
I equals one I less than what equals gay and I placeless.
Scout, Bacolod Top.
And Bechard artpop.
And we know the output is going out before this area is five Trenta, but the output will come out unsorted,
so the output will be two, three and five, correct?
So you can see.
Earlier, I was using Makhzoumi, so my output was just the reverse of this five, three and two, but
here I am using minimum heap, so the output is two, three and five.
So two, three and five at the three smallest element present in this given area.
So that's how we can use minimum hyp.
So I think I have discussed the time, complexity, all sorts of decisions and log in and this is key
log and correct.
Now, this question was to find.
So this question was to find the smallest element, so let's say the maximum priority queue was giving
me the best time in space complexity.
Now, if the question is to find the just element.
If the question is to find the killer element, so it is very obvious that the minimum help will give
me the maximum, the minimum, it will give me the best time and space complexity.
I am repeating myself in this question.
We have to find the smallest element.
So that's why the employer was giving me the best approach, because I will maintain the size.
The size will be key.
If the question is this one, then I will lose my employer.
You and I will maintain the size of an employer to Kyuki.
Now in this question also, so, for example, the question is just if we want to use Mixin prior to
you, you can definitely use what you will do.
You will push every single element.
So you will push every single element inside your priority queue.
So time, complexity and Logan and then what you have to do so we won't get so I will pop out key elements.
So these key elements will be the largest element.
So Kellogg, Kellogg and.
Simple so in this question, if you will choose to make simpler, to do everything will just become
a perceived.
So simpler to dismiss time, complexity and I mean practical will give me and longer time complexity.
Now, there is one more way to insert elements into your priority queue, so first tell me, how much
is the time complexity for this call?
What I am doing so I am creating a minimum priority queue.
And then I am reading over the air and I am inserting elements into my priority given by one element
of time, complexities of time, complexities and Logan.
Just remember, this time, complexities and Logan, now there is one more way to insert elements into
your priority queue.
So instead of writing, so let's copy this one now, I just need the first line.
So the above code was inserting the elements time, complexity was analog and.
Now, if you will insert the element in this, we.
Acoma, Apison.
So now the time complexities go off and.
Maritime complex, it is big often, so let's test our record.
So, see, our report is correct, two, three and five.
Our goal is working fine.
So if you will insert the elements in this way, one by one, I'm inserting the elements one by one.
So there are time complexities going to be and Logan.
So what is the difference between this method and this matter?
The workers say they are just inserting the elements inside your priority queue, but what is the difference?
So in this approach, what we are doing, we are taking elements one by one.
Elements are coming one by one.
But in this way, what we did, we provided just Holyday Edwards, we provided all the elements at once,
so that's why the time complexity decreases.
So here the time complexities Magoffin and the time, complexities and Log-in similarly.
If so, if you want to insert vector, for example, instead of ETTY, if we're using vectors of what
we will write, we will write vector dot begin.
Basically, we have to give the first and the last address to begin and end.
Instead of writing a plans and just like in these sorting function, sort my person or you can write
Saat we begin Victor not we begin my view.
So there is no need to go into much detail by the time complexities is often probably.
I will just create one video to explain to you by the time complexities big.
And so for now you can just remember that if you look at it prior to you using this matter, perhaps
the whole idea was then the time complexity for inserting the elements as big often and then wasted
time complexity.
If the elements are coming one by one, then the then your time complexities and log-in.
So just remember this time complexity.
I will just probably create one more video explaining why it is so.
OK, so this is how you can use minimum priority.
You just remember this index.
Everything will work fine.
So what is this trained teacher?
So what I will do, I will upload some notes and you can at those notes, but frankly telling you there's
no need to go into detail why this is so.
Just remember the syntax and do the work.
Nothing much.
So I will see you in the next one by.