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?

Answer: A. O(1)Array elements can be accessed directly if the index is known, hence the time complexity is O(1).

  1. A.

    O(1)

  2. B.

    O(n)

  3. C.

    O(n log n)

  4. D.

    O(n^2)

Attempted by 1503 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).

Explore the full course: Coding For Placement

Loading lesson…