What is the time complexity of accessing an element in an array by index?
What is the time complexity of accessing an element in an array by index?
Choose an Option
Answer
O(1)
Theory
Arrays store elements in contiguous memory locations, allowing direct address calculation: address = base + i × size.
Solution
Direct address arithmetic gives constant-time access. Answer: O(1).