An array gives you four basic operations. Two of them are effectively free, and two of them get more expensive as the array grows. Knowing which is which is most of what separates a fast solution from a slow one.
Reading ages[3] or assigning ages[3] = 22 takes the same amount of time regardless of whether the array holds ten values or ten million. The machine computes where slot 3 lives and goes straight there — it never looks at the other slots.
Free account
Sign up to read the rest of this lesson: 3 more sections, 1 drawing and code in 1 language.
Still to come