What is the Big-O time complexity of accessing an element by index in an array?
Options
- A. O(1)
- B. O(log N)
- C. O(N)
- D. More than one of the above
- E. None of the above
Quiz Practice:
A. O(1)
Accessing an element of an array using its index generally takes O(1) time because arrays provide direct or random access. The address of an element can be calculated using its base address and index. Therefore, accessing arr[5] does not require examining the elements before it. This differs from a linked list, where accessing the element at a particular position generally requires traversal and can take O(N) time.