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. The reason nums[i] is instant is worth knowing rather than accepting: the items are the same size and sit in one unbroken block, so the machine computes the address arithmetically as base + i * itemSize and goes straight there. No searching, no following anything. That one multiply-and-add is the whole of random access, and it is why the index starts at 0 rather than 1, since the first item sits at base + 0.
The rest of this lesson continues with 5 further sections. See the full curriculum.
Browse all 546 practice puzzles