A lesson from the Data Structures module of the bootcamp. About an 11 minute read.
An array is an ordered list of items stored back to back in memory. It is the most common data structure, the one most problems start from, and the only one whose speed comes from the hardware rather than from the idea.
An array is a numbered sequence of values, with indices starting at 0. Why is nums[i] instant? It is worth knowing rather than accepting. Every item is the same size and they all sit in one unbroken block, so the machine computes the address directly as base + i * itemSize and jumps straight there. No searching, no following anything. That one multiply-and-add is all random access is. It is also why the index starts at 0 rather than 1: the first item sits at base + 0.
The rest of this lesson continues with 5 further sections. See the full curriculum.
Browse all 576 practice puzzles