We assume that inserting and copying elements between arrays takes time.
We will choose , doubling the array size every time the array is full.
Now, when there is space in the array, insertion takes time. When the array is full, however, it grows from to elements and requires copying elements.
e.g. when we start with an array of size , the array doubles
This is a geometric series, and the copy costs are
Thus, the copying of elements takes time and the insertion of elements takes amortized time, which translates to
amortized constant time per insertion.
2) removing
We assume that removing elements also takes time.
We can choose to halve the size of the array (which still has length) every time the number of elements frops below of the array's size.
Suppose we start with an array of size , and the number of elements falls from to . In this case, we shrink the array and copy elements to the new array.
Thus, we come to a total number of copy operations of
Equivalent to the argumentation for copying and inserting elements, copying and removing elements also takes amortized time, i.e. constant time per element.
inserting + removing
Since inserting and element takes and deleting also takes , inserting + removing also takes amortized constant time.