What is the time complexity of accessing the element at a given index in an array?
Correct answer C. O(1)
Explanation
Array elements are stored contiguously and are all the same size, so the address of element i is computed directly as base address plus i times element size. This arithmetic takes constant time regardless of the array's length. O(n) is the cost of reaching the i-th node of a linked list, where you must follow pointers one by one.
Answer checked How we write and check questions
Discussion