According to Wikipedia, accessing any single element in an array takes constant time as only one operation has to be performed to locate it.
To me, what happens behi
An array starts at a specific memory address start
. Each element occupies the same amount of bytes element_size
. The array elements are located one after another in the memory from the start address on. So you can calculate the memory address of the element i
with start + i * element_size
. This computation is independent of the array size and is therefor O(1)
.