O(1)
In an array, index
of 0 (base address)
has a memory address
.
n-th index number
and size of one element
, you get a memory offset valueoffset value
to the base address
, we can fetch the memory address of the n-th index value
This way, you don't have to iterate through the array and the lookup time becomes O(1)
.