What is the time complexity for accessing an element by index in a standard contiguous array?

Prepare for the TJR Bootcamp Test with quizzes and flashcards. Each question includes hints and explanations to boost your readiness for the exam!

Multiple Choice

What is the time complexity for accessing an element by index in a standard contiguous array?

Direct indexing in a contiguous array is constant time. Because elements are laid out one after another, the position of any element can be found with a single calculation: base address plus index times element size. This means you fetch that memory location in one step, regardless of how many elements the array contains. So the time to access is not affected by n, giving O(1).

O(n) would imply traversing elements until you reach the target, which isn’t necessary here. O(log n) or O(n log n) would apply to searched or hierarchical structures, not to direct index access in a flat array.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy