Neocortex 🧠

Search

Search IconIcon to open search

Dynamic Arrays

Last updated Nov 23, 2021 Edit Source

Normally, adding an element to an already full Array would take $O(n)$ time, if you resize it by 1 cell everytime an element is added, that is. However, when you extend the array by the number of elements there are in the array everytime it is full, the time complerxity drops to $O(1)$.

The time complexities of element additions for size of dynamic array:

1234567891011121314151617
121411181111111161

In total, summing up the lower row of the table gives us $2n$ operations for an array of size $n+1$. In order to calculate the amortized time complexity of this data structure we just take the average:

$$\frac{2n}{n+1} \cong 1$$


Interactive Graph