Hello, everyone, so I'm going to talk a little bit more about Vector's, how they work, so let's
say you create a vector and by default, let's say it has some size.
So in there still vector, the size is actually zero.
But let's let us assume you have a vector of letter size forward.
That means the array can accommodate up to four elements.
Let's say one, two, three, four.
Now, you want to insert one more element in this vector, that is five, what this vector will do.
It will double itself.
OK, so it is going to double itself.
So what is going to happen actually is a new vector.
A new eddy would be created at some other part of the memory.
This location is one zero zero and maybe at some other location later to 760, a new ETA is created.
And it's in this area has a size it.
OK.
So what I'm trying to tell you is if the original side of the work that is X, then the new size would
be two X, and this is a dynamic at this memory can be freed up.
This vector will be all the elements from the previous location into the new location, and it will
also insert five at this particular location.
OK.
So this is what this victory.
This is how the victory actually grows itself.
OK, and once the new weapon is created and all the elements have been copied.
This ad is deleted, OK, so the memories freed up and this is where the new rectories, though, all
of this can happen automatically if you use the container class that is provided by the.
Still, if you don't use it, then we have to build this functionality in our own regardless.
I suppose you keep on inserting more elements.
It's a six, seven, eight.
Now, again, it is full.
It will again double itself.
And you will see.
The size of the vector is now 16 and stored up to 16 elements.
OK, again, the size will become 2x Aletta for X, OK, so every time the vector is going, I'm going
to get full.
It is going to trouble itself.
And this doubling helps the victor to accommodate more elements and grow in size.
So what would be the complexity of pushing an element of a vector?
OK, so if you look back at them pushing an element to the end of the vector, so for most operations,
it is going to be order one, but in some cases.
In some cases.
It is going to be ordered off and as well, because you are going to copy all these elements here,
which is going to take order and time, then you're going to insert nine in the vector.
OK, so that's that's why it's going to be harder and in some cases.
But what we can do, we can find out the average time complexity or the amortised.
I'm complexity on an average, how much of it is going to take OK for every insertion?
Now, you can also reduce this doubling by if you know that you are going to get at least 1000 element.
So what it is preferred is you initialize your vector with our inboxes and then if thousand exceeds
only the new look.
So that means if your data is going to contain fifteen hundred elements, only one time you're going
to double and Alderton operation 4000 elements.
So you're doing all that and work once or an element that means on an average or one element you are
just going to do end up on end.
That is like order one.
So on an average, the pushing is going to still work in order one time.
Or what you can do is you can.
OK, so what I'm trying to show you is there is this Web site, C++.
And dotcom and this has a very nice documentation about all the steel containers that we are going to
use.
So if you're confused about some function or some great asset, you can definitely look up at this documentation.
For example, I want to look at the push back function of a vector.
So it tells us this washbag functions are the new element to the end of the vector after the last element
and the values copied to a new element.
OK, and this increases the container size by one which causes an automatic reallocation of delegate
space if and only if the new vector surpasses the current vector capacity.
Because as I said, Vector is going to contain two things.
Let's say this is one, two, three, four.
So the capacity of the vector is it?
But the size the number of elements is just for one to exceed the capacity, only then the reallocation
of memory is going to happen.
OK, and what is the what is the.
So this is a demo we will see very soon.
And what is the complexity of this pushback function so you can see this constant on an average and
relocation may happen in some cases and it is written for the allocation happens, the relocation itself
is actually not intended.
OK, so I hope now you understood this fact.
It's an important thing.
You understand why the relocation happens and why it is taking linear time when it is doing relocation.
OK, but if you initialize it properly, the relocation may not be that frequent.
You can say it is going to work in order one for most cases.
So that's the whole idea, and this is a little weird introduction about how actors work, and next
we will see their demo and then we will dive into the implementation.
That's it.
Thank you.