Technology Fundamentals
Array
Definition
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.
Why It Matters
Arrays are one of the most simple and fundamental data structures. They provide fast, O(1) random access to elements based on their index, making them highly efficient for many use cases.
Contextual Example
A list of daily high temperatures for a month can be stored in an array. To get the temperature for the 15th day, you can directly access the element at index 14 (since arrays are typically zero-indexed).
Common Misunderstandings
- Arrays typically have a fixed size that is determined when they are created. Dynamic arrays (or lists in some languages) can grow and shrink, but this may involve reallocating memory behind the scenes.
- Inserting an element at the beginning or middle of an array is slow, because it requires shifting all the subsequent elements over.