Before we can talk about arrays, we need a working picture of where a program keeps its data. Not a precise hardware diagram — a simplified model that is accurate enough to predict what your code will cost. Almost every claim in this course, including why reading arr[i] takes the same time no matter how large the array is, follows from this one model.
Start with the smallest interesting thing a computer does: adding two numbers. The CPU holds a handful of tiny slots called registers, and an arithmetic unit that can add the values sitting in them. Feed it 10 and 6 and it produces 16.
But registers number in the dozens, not the millions. The moment the CPU needs that 16 again later — or needs to hold a thousand values at once — it has to put the result somewhere else. That somewhere is main memory, or RAM.
Picture RAM as one enormously long row of numbered slots. Each slot holds a fixed, tiny amount of data — one byte — and each has a permanent number called its address. The addresses run in order, with no gaps, from one end of memory to the other.
The CPU's conversation with memory is narrower than you might expect. There are only two operations, and both take an address:
The critical property is that both operations cost the same regardless of which address you name. Reading address 1003 is no faster than reading address 4,000,000,003. Memory does not scan from the beginning to find a slot — the address is wired directly to the hardware that holds it, which is exactly why it is called random access memory.
Hold on to two facts: addresses are consecutive integers, and reading any address costs the same. An array is what you get when you take those two facts and lay out a group of same-sized values one after another. Because the values are evenly spaced and the first address is known, the machine can compute the address of any element with a single multiplication and addition, then do one constant-cost read.
That computation — address = start + index × size — is the whole reason arr[i] is an O(1) operation, and the next lesson builds it up step by step.