Skip to main content
Glossary Term

Array (data structure)

History and Applications of Arrays - First array-sorting program (merge sort) written by John von Neumann in 1945 - Early array indexing done by self-modifying code - Some mainframes in the 1960s used memory segmentation for index-bounds checking - High-level programming languages like FORTRAN, Lisp, COBOL, and ALGOL 60 had support for multi-dimensional arrays - C++ introduced class templates for fixed and runtime-flexible multi-dimensional arrays - Arrays used for mathematical vectors, matrices, and rectangular tables - Many databases consist of one-dimensional arrays with record elements - Arrays used to implement other data structures like lists, heaps, hash tables, queues, stacks, and strings - Arrays used for in-program dynamic memory allocation - Arrays used as control tables to determine program control flow Element Identifier and Addressing Formulas - Indexes (subscripts) used to select individual objects in an array - Three ways to index elements: zero-based indexing, one-based indexing, and n-based indexing - Zero-based indexing is a design choice in influential programming languages like C, Java, and Lisp - Arrays can have multiple dimensions, requiring multiple indices for access - The number of indices needed to specify an element is called the dimensionality or rank of the array One-dimensional Arrays - One-dimensional arrays are linear arrays with a single subscript for element access - Subscript can represent a row or column index - Accessing elements in a one-dimensional array is straightforward - One-dimensional arrays are commonly used in various applications - Can be implemented efficiently with little space overhead Array Data Type - Array data type provided by high-level programming languages - Collection of values or variables selected by one or more run-time indices - Array types often implemented by array structures, hash tables, linked lists, search trees, etc. - Array data type can be implemented using various data structures - Array data type is an abstract data type capturing essential properties of arrays Multidimensional Arrays and Efficiency - Addressing formula for element with indices: - Formula: base address + (row * row address increment) + (column * column address increment) - Example: int a - Array has 2 rows and 3 columns - Elements stored linearly, starting from first row to second row - Static arrays have a fixed size and do not allow insertion or removal of elements - Dynamic arrays can be implemented by allocating a new array and copying contents - Insertions at the end of the array require amortized constant time - Store and select operations on arrays take constant time - Arrays take linear space in the number of elements they hold - Sequential iteration over an array is faster due to locality of reference - Arrays have no per-element overhead and are memory-wise compact - Optimized routines like memcpy can significantly speed up copying array elements