what is a dynamic array

what is a dynamic array

1 year ago 41
Nature

A dynamic array is a data structure that allows for the creation of a random access, variable-size list that can have elements added or removed. It is also known as a growable array, resizable array, dynamic table, mutable array, or array list. Dynamic arrays are supplied with standard libraries in many modern programming languages. They overcome the limitation of static arrays, which have a fixed capacity that needs to be specified at allocation. A dynamic array is not the same thing as a dynamically allocated array or variable-length array, either of which is an array whose size is fixed when the array is allocated, although a dynamic array may use such a fixed-size array as a back end.

A simple dynamic array can be constructed by allocating an array of fixed-size, typically larger than the number of elements immediately required. The elements of the dynamic array are stored contiguously at the start of the underlying array, and the remaining positions towards the end of the underlying array are reserved or unused. Elements can be added at the end of a dynamic array in constant time by using the reserved space until this space is completely consumed.

Dynamic arrays benefit from many of the advantages of arrays, including good locality of reference and data cache utilization, compactness (low memory use), and random access. They usually have only a small fixed additional overhead for storing information about the size and capacity. This makes dynamic arrays an attractive tool for building many types of applications.

Read Entire Article