Is access time in the array is O(1)?

Bhavani shanker
2 min readJun 28, 2021

--

lets us the memory allocation in the array, when an array of size n is declared a certain continuous block of memory is allocated for that.

Array indexing starts from 0

for example when an array of size 5 declared each unit occupying 2 bytes and memory continuous block if started from 1000 then allocated memory is from address 1000 to 1008

The base address of the array is stored as a reference for that array
and each element here is accessed from the base address. here the Base address = 1000.

Accessing nth element : Base address (unit_memory_size ) * n

Let us see in detail:
accessing 0th element : 1000 + (2 ) * 0
accessing 1st element : 1000 + (2 ) * 1 = 1002
accessing 2nd element : 1000 + (2 ) * 2 = 1004
accessing 3rd element : 1000 + (2 ) * 3 = 1006
accessing 4th element : 1000 + (2 ) * 4 = 1008

Thus accessing time of any nth element in the array is of O(1)

--

--

No responses yet