What is the time complexity for accessing an element in an array if the index…
2023
What is the time complexity for accessing an element in an array if the index is known?
- A.
O(1)
- B.
O(n)
- C.
O(n log n)
- D.
O(n^2)
Attempted by 1036 students.
Show answer & explanation
Correct answer: A
Array elements can be accessed directly if the index is known, hence the time complexity is O(1).