Suppose that a precisely sized array is used to hold data, and that each time the array size is to be increased, it is increased by exactly one and the data are copied over.
Prove that, in the process of growing an array incrementally from size $0$ to size $n$, approximately $n^2$ values must be copied.
so here what I have tried. p.s I have no idea what I am doing here. I get that in order to loop though array of numbers than the timing is $n$.
[1] = 1 value
|
[1, 2] = 2 values
| |
[1, 2, 3] = 3 values
| | |
[1, 2, 3, 4] = 4 values
| | | |
[1, 2, 3, 4, 5, ..., $n$] = $n$ values
Okay so for n=2, you have n-1 (1) copies.
For n=3 you've got an ADDITIONAL n-1 copies (2)
For n=3 you've got an ADDITIONAL n-1 copies (3) ......
You just have to sum your
|sAs you should know:
That's where your squared comes from in the complexity.
See it now?