What is the asymptotic growth of the number of copies requir

What is the asymptotic growth of the number of copies required by the amortized doubling technique used by std:vector? That is, for a vector that has grown to length n, how many elements have been copied as a result of running out of space as it grew to size n? (Use big-O notation).

Need help with the solution, not definitions plss!!!!!

Solution

1. Lets say there is a vector whose size is N
2. Now when the N+1 element is added
3. The vector size needs to be doubled i.e size 2N and all the N previous elements has to be copied into new vector of size 2N.

So if we consider the amortized cost , which is the average cost over many insertions.
So, when N+1 element is added , N copies are done then for further N-1 element there is no resize .

Thus the number of copies for N elemnets is N.
So if we consider the amortized cost , which is nothing the average cost over many insertions.
Thus the amortized cost is average of N copies divided by total number of insertion i.e N
So amortized cost is O(1)

What is the asymptotic growth of the number of copies required by the amortized doubling technique used by std:vector? That is, for a vector that has grown to l

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site