What is the time complexity of accessing an element in an array by its index ?
2025
What is the time complexity of accessing an element in an array by its index ?
- A.
O(1)
- B.
O(log n)
- C.
O(n)
- D.
O(n2)
Attempted by 130 students.
Show answer & explanation
Correct answer: A
Array element access by index is a constant-time operation because the memory address can be calculated directly using base_address + (index * element_size). This means regardless of array size, the operation takes O(1) time.