We have claimed twice now that reading ages[3] is instant no matter how big the array is. That claim should feel slightly suspicious — how can finding one slot among ten million take no longer than finding one among ten? This lesson shows the trick, and it is genuinely just arithmetic.
Recall from the memory-model lesson that memory is a long row of numbered slots, and that reading any address costs the same as reading any other. Add two design decisions from our array, and the trick falls out:
Free account
Sign up to read the rest of this lesson: 2 more sections and 1 drawing.
Still to come