data-structures

Definition

Array

An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored such that the position of each element can be computed from its index tuple by a mathematical formula.

In most low-level implementations, an array is a contiguous block of memory.

Memory Layout

The fundamental characteristic of an array is its contiguous allocation in memory. This allows for constant-time access to any element via its index.

The memory address of an element at index can be calculated as:

Complexity

The following table outlines the time complexity of standard array operations:

OperationStatic ArrayDynamic Array (Vector)
Random Access
Insertion (at end)
Insertion (at start)
Deletion
Search (unsorted)