Hi, everyone.
So in the last video we implemented, these three functions get the minimum is empty and to function.
So in this video, we will focus on insert function.
We will try to write the code for insert function so how we can insert elements.
Let us take an example.
So suppose you have this minimum heap and these are the values.
Now, suppose you want to insert an element what you will lose or you will call a function insert and
you will pass the value.
For example, you want to insert tool.
So 12 will be inserted at this position.
So let us socialize it, let us feel the values in our area.
So this is my priority character.
So this 10, 50, then 20, then 60, then under and then 25.
So what will happen?
12 will be inserted at the last point.
So this is zero one, two, three, four, five and six.
So 12 will be inserted at the next six.
So let's do that first.
So I'm using Vector.
So first let us include Vector also.
So I want to create a function inside so the return will be void.
I will not done anything.
Now this and third function will take integer as input, the element that we have to insert.
And what we have to do so we have to ensure that the last element at the last minute, we have to ensure
that Elastin Nixa wavefunction be accurate, pushed back.
So this push back function is in brain function of.
Our Victor and I have inserted the element now after inserting the element of a CBT property is correct,
so it is complete by Nutri, so CBT is correct, but he property is invalid.
He bought the property is not satisfied.
So as you can see, so Glenn is actually less than 20, so what we have to do, so these are the indexes
zero one, two, three, four, five and six.
So instead of this writing every time, you can write indexes here also.
So what does my child index?
So this is in Mexico.
So in the last video, we discussed that.
If parent index is a, then it's left children nexus to opalescent and it's Rachell Index is actually
duopolies.
And if you want to go back towards your parent index.
So in order to find out pend index.
So this is very simple.
Giler index minus one by two and you will be able to find out the apparent index.
So what we have to do.
So my child index is six.
So this is index and what is my band index to parent index is to you can apply this formula.
So six minus one battle band index is to then they have to do you will compare the values you will compare
to you will compare twenty with twelve.
So twelve is less than 20 then.
Do you have to do something.
So will come here and they will come here, so we have to do something.
So what is the challenge?
First of all, we need to find out child index.
So child index is actually the last element you can see.
So the last element reinserted and how we can find out.
So basically there are total seven elements.
So Picador says that will give me seven minus one six.
So Picador ties total number of elements, minus one.
I will be able to find out.
Drylands so beginner size again sizes and build function of vector and minus one.
So in this way, I will be able to find out my challenge next.
Now what we have to do.
So I have to find out beyond the next.
So what is next?
Again, this is a very simple formula.
We have discussed many times.
So this is child X minus one.
By two to now we know better next and next, so we are doing all this work because our property is not
satisfied.
CBT properly certified, but he probably is not satisfied, you can see, so we are doing all this work
so that our property becomes satisfied.
So I'm writing here he probably not satisfied CBT properly certified, so Sebelius heap not, then why
do they have to do so?
I have to compare those values.
So if basically the child value.
It's less than parenteral.
So if the child values less than parent value, so see this example?
So 12, 12 was actually less than 20, so if the child value is less than the parent value, then you
have to do something.
So let's do shopping.
So we have inbuilt function SREP and we can pass these values.
Charlie Index and.
Parent Alex.
So we have done this weapon once.
So what is the scenario?
So this tunnel and it's been 20, so they are now well presented and 20 is presented.
So we should stop at this point or not.
So we should not stop at this point because now we have to compare well with 10.
So what is the index of to allow.
So it is basically.
Our new challenge is to know you can see the index of 12 is actually two, so this is my new index again.
I will find out my pain index, which is zero.
I will apply this formula.
So the index is two to minus one by two.
So it all came out to be zero.
So bad index is zero.
Then I will compare.
Well, and then so I have to compare well and then again and so they can be one more scenario.
Let us take one example.
So suppose instead of two I want to push zero.
So let me take one example.
So I have this little 10, then 20 or 200, then let's say 30 or so and let's say I have 50 here.
Let's say 150.
And these are indexes zero, one, two, three, four and five.
Now I want to insert an element.
Let's say I want to insert zero.
So I want to do a certain element and also the indexes.
So what I will do so this is my child index.
This is my index.
So compare, so general index is six and recipient index.
So, again, apply the formula.
So this is six minus one two.
So it will come out to be two.
You can see.
So again, now compare.
So compare zero and hundred, so zero is smaller, so I will slap.
So after stepping what will happen, the new index of zero is to show the new index of zero is to now
we will again find out its index.
So its index is zero.
So apply the formula to minus one vital sorbent index in zero.
So this is zero period index now comparing.
So zero is actually less than 10.
So you will have to snap again.
So I will again do something.
So this is actually 10.
And this will become zero.
So again, now this zero has an extra.
So, again, this zero will come here and spend the next.
So basically zero is our topmost element.
This is the smallest index.
And we will stop, so at this point, there is no element to compare with, so whenever the child index
will become zero, I will stop.
When the index will become zero, I will stop.
So this is the first stop in coalition and the second stopping nation is actually this one.
So here, if you will, compared to oil and then so actually ten is less than 12.
So you do not have to do something.
So this is my second stopping criteria.
So if the index is good, then index values good, then index value in this case.
So this is 12.
So 12 is actually good than 10.
So you can stop.
So we have to stop in great ideas first.
I will reach at the topmost element, root element, and second, if the child value becomes bigger
than the parent value, so we are doing all this work to satisfy our property.
We are doing all this work to satisfy our property, our complete binary tree property has already been
satisfied.
Simple.
So let's do this.
So we have to do this work repeatedly.
But they have to do so for us to stop criteria's so vile child index.
Is a good zero.
So I am finding out the challenge index, so while juggling decks is good.
Find out the parent index, compare those two values.
So if the value is smaller, you can swipe and your next index now your child index will become parent
index.
In the part, what you can do, you can break so there's no need to continue.
You can simply break.
So I think this court should work fine, so let us take an example.
So let's say this is my hip then then it's a 20, so I have to here and then let's say I have 40, 50
and 60.
So this is my hip.
And now I want to insert an element.
Let's say I want to insert 25.
So these are my indexes, zero, one, two, three, four and five.
So if you want what you can do, so you can.
Create a vector and you can push and you can write all these elements here.
But writing a indexes on the values, so this is a much shorter way to explain things, so I want to
insert an element, 25 to 25 will be decided at this position.
At Index six.
So what is my child index so big your size sizes seven, so there are seven elements minus one, so
jelly index is actually six.
This one, the child index is six.
Now wait till next is good than zero six zero zero.
Find out the parent index.
So parent index is actually do so.
Parent Index is two now compares.
A child's index is less than an index of 25 is less than 30 years.
Do the shopping part then.
I will come here and they will come here, so self-deception, so the new child index is actually parent
index.
So what is the index?
It is.
So, yes, the new index is two and then we will go above.
So child index is actually two.
So two is bigger than zero.
Yes, it is true.
Then we will do so if I now depend inexpedient indexes zero.
Then compare child value with different values or 25.
That is actually good.
Then 10.
Now we will reach the l'esprit.
Twenty five is basically guerdon ten.
So I will reach the Elzbieta and I will break so I will come out of the slope and twenty five has been
inserted.
And in this area if you can see.
So this 30.
And I inserted 25 that are gender and wife has been stabbed, so 25 is had Antabuse here.
So that is how this is working.
Now, let's take one more example to understand this question to never.
So this time, let's take this example.
So when there are three, then let's say I have four, then five, and then we lose six.
So these are the indexes of the vector.
So zero, one, two, three, four and five.
Now I want to insert an element zero or let's say I want to insert an element minus one.
So what happens minus one will be inserted at this position and its index is six.
Simple.
So what do we do?
So Child Next came out to be six Viljoen, next is a good than zero.
Six is actually greater than zero.
Find out the next two parent indexes to then compare the child value with the parent value.
So minus one is less than three.
You will do something so trivial.
Come here and my next one will come here.
Then you are updating your child index.
So which is parent index.
Parent index was two, so the index of minus one is actually two now.
So again, Gile index is two, so you will find no dependent expert index will came out to be zero again.
You will do the comparison to compare minus one and one.
So minus one is smaller, you will lose something.
So minus one will come here and one will come here.
Then you will upgrade your child index with the pandemic Sabella index next zero, you can see behind
the next zero.
So your child index now becomes a zero.
Again, you will go at the top and this time this condition.
So the condition inside develop will become false because the child index is zero now, and that's how
we will be able to insert minus one adult's right position.
So our monetary properties were satisfied at this point only, but we have to satisfy the property.
So that's why I have to write this much code.
Simple.
So in the next video, we will write the Code four, remove minimum function.
I will see you in the next one.
Bye bye.