What is the time complexity of accessing an element at a given index in an array?
Options
- A. O(1)
- B. O(n)
- C. O(log n)
- D. More than one of the above
- E. None of the above
Quiz Practice:
A. O(1)
A starts at a known address and each element occupies the same amount of memory, the address of A[i] can be calculated directly. This is called random access and is an important advantage of arrays over linked lists.