Array
An array stores a sequence of values in indexed positions. Its size is commonly fixed when the array is created, which makes it a good fit when the number of items is known or bounded.
In the help desk case study, the team has exactly four scheduled on-call slots. This is a real capacity constraint, so an array expresses the requirement directly. See Data structure decisions for the operation that led here.
Most arrays use zero-based indexing. That means the first element is at index 0, the second is at index 1, and so on. The index is a position, not the value stored at that position.
on_call_slots = array with capacity 4
on_call_slots[0] = "Mina"
on_call_slots[1] = "Owen"
Reading or replacing a value by index is usually O(1). Searching for a value is O(n), and inserting into the middle requires shifting later values. Use an array for fixed-size records, tables, buffers, or other data where direct indexed access matters.
Reading or replacing a value by index is usually O(1). Searching is O(n), and inserting into the middle requires shifting later values.
The array is not a good report log: a fifth specialist or an unexpected volume of reports would exceed its capacity.
See Array examples for runnable examples in supported programming languages.