Arrays are a fundamental data structure in programming, but many developers misunderstand how they actually work under the hood. The key insight: arrays don't 'walk' through memory to find an element — they jump directly to it.
When you access an array element (e.g., arr[3]), the computer uses a simple formula: base_address + index * item_size. This calculates the exact memory location in constant time, O(1). That's why array access is so fast and why we call it "random access" — you can jump to any position instantly.
This is possible because array elements are stored contiguously in memory. The computer knows the starting address (base) and the size of each item, so it can compute the address of the desired index by multiplying the index by the item size and adding that offset to the base.
Understanding this is crucial for writing efficient code. It explains why searching by value (linear search) is O(n) — the computer must check each element sequentially — but accessing by index is always O(1).
In contrast with arrays, inserting or deleting an element in the middle can be expensive because elements after the insertion point must be shifted. This is the trade-off for fast access.
Next, we'll explore insertion in arrays and why adding an item in the middle costs time.