why does accessing an element in an array take constant time?

The array, effectively, is known by a memory location (a pointer). Accessing a[3] can be found in constant time, since it’s just location_of_a+3*sizeof(int).

In C, you can see this directly. Remember, a[3] is the same as *(a+3) – which is a bit more clear in terms of what it’s doing (dereferencing the pointer “3 items” over).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)