Array Access Complexity

data-structures, java, optimization, time-complexity

Solution

For large values of array1 size N can I assume each single array access (array1[index]) takes constant time?

In Java, yes. Also in C, C++, and C#, barring OS-level memory paging issues that are presumably out of scope.

Does this access time depend on language( java vs C++) or the underlying architecture ?

It can, if the language in question calls things "arrays" that aren't really arrays in the usual "contiguous block of memory" sense. (JavaScript does that; its `Array` (`[]`) type is really a map; PHP uses the term "array" as shorthand for "associative array" [e.g., map].) So for a given environment/language, it's worth checking that the term isn't being misused or used loosely.

Problem

In Java supppose I need to access `array1[index]` many times in the code. Even for extremely large arrays, can I assume each single array access takes constant time? Can this differ between languages or underlying architecture?

Original source

Related problems