Arrays

What Are Arrays?

Arrays are ordered collections of elements stored at contiguous memory locations, each element identified by one or more integer indices and accessible in constant time through direct address computation. As a foundational data structure in computer science, arrays provide the simplest and most efficient means of storing sequences of homogeneously typed values, from integers and floating-point numbers to structs and pointers. The contiguous memory layout enables cache-friendly sequential access and makes arrays the natural substrate for implementing vectors, matrices, tables, strings, and a large fraction of higher-level data structures such as hash tables, heaps, and ring buffers. Arrays are among the oldest data structures in programming, appearing in the first stored-program computers: John von Neumann wrote the first array-sorting program (merge sort) in 1945 during the development of the IAS machine at the Institute for Advanced Study in Princeton.

The term "array" appears in both software and hardware contexts. In software, an array is a first-class construct in most programming languages, with dedicated syntax for declaration, indexing, and iteration. In hardware, the term extends to physical arrangements such as phased-array antennas, sensor arrays, and array processors, all of which share the defining property of indexed, regularly spaced elements.

Array Data Structure

A one-dimensional array of N elements of type T occupies N * sizeof(T) consecutive bytes in memory. Given the address of the first element (the base address) and the index i, the address of the i-th element is computed as base + i * sizeof(T), a formula that takes a fixed number of operations regardless of N, giving O(1) random access. Insertion and deletion in the middle of an array require shifting subsequent elements and are therefore O(N) operations, a cost not present in linked-list structures. Dynamic arrays (called vectors in C++ or ArrayLists in Java) extend static arrays by maintaining a capacity larger than the current element count and doubling the allocation when the capacity is exhausted, amortizing the O(N) reallocation cost to O(1) per insertion on average. The Britannica reference on arrays in programming languages describes how array syntax and index conventions differ across languages, including zero-based (C, Python, Java) and one-based (Fortran, MATLAB, Lua) indexing.

Multidimensional Arrays and Matrix Representations

Multidimensional arrays generalize the one-dimensional structure to two or more indices, representing matrices, tensors, images, and volumetric datasets. A two-dimensional M × N array can be stored in row-major order (C convention, where elements of each row occupy consecutive memory locations) or column-major order (Fortran convention, used in MATLAB and LAPACK). The choice of storage order affects performance significantly for operations that traverse the array in one dimension at a time, because modern processors fetch memory in cache lines and sequential access within a cache line is far faster than strided access across lines. Sparse arrays, in which most elements are zero or otherwise absent, are represented efficiently through formats such as compressed sparse row (CSR) or compressed sparse column (CSC), which store only the nonzero values and their indices. The Basic Linear Algebra Subprograms (BLAS) and LAPACK libraries, documented by Netlib, define standardized interfaces for dense array (matrix) operations used across scientific computing.

Arrays in Hardware and Memory Architecture

In processor architecture, array-like structures appear in register files (the indexed set of general-purpose registers), cache tag arrays, and translation lookaside buffer (TLB) arrays. Vector processors extend the scalar register file with large vector registers that can hold and operate on arrays of 64 to 512 elements in a single instruction, implementing single instruction multiple data (SIMD) parallelism. The RISC-V Vector extension and ARM's Scalable Vector Extension (SVE) represent modern approaches to variable-width SIMD, allowing the same code to adapt to different hardware vector lengths. Field-programmable gate arrays (FPGAs) and application-specific integrated circuits exploit systolic array architectures in which processing elements are arranged in a grid and pass data to neighbors, achieving high throughput for matrix multiplication and convolution workloads.

Applications

Arrays have applications across computing and engineering, including:

  • Numerical linear algebra: matrix factorizations (LU, QR, SVD) for solving linear systems and eigenvalue problems
  • Image and video processing, where pixels form two-dimensional or three-dimensional arrays
  • Signal processing: FFT algorithms operate on one-dimensional arrays in O(N log N) time
  • Machine learning: neural network weight tensors and activation arrays stored as multidimensional arrays
  • Database systems: columnar storage formats represent table columns as arrays for vectorized query execution
Loading…