1
$\begingroup$

Why do most implementations of arrays have constant access time and linear insertion time?

$\endgroup$
3
$\begingroup$

Because they are using the pointer to access to an index of the array, hence the access time is constant. Moreover, as indices of the array are stored beside each other (to access in constant time), insertion to the array needs to extend the allocated storage of the array to insert a value, and it needs to copy all values of the array to the newly allocated storage with size $n + 1$. Hence, insertion of the array is $O(n)$ in most of the implementations.

To know more about this, you can seek around "dynamic array" for constant access time and amortized $O(n)$ for $n$ insertion.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.