Data Structures & AlgorithmsEasyTCS NQT · Infosys pattern

What is the time complexity of reading the element arr[i] from an array of n elements, given i?

  1. A. O(1)
  2. B. O(n)
  3. C. O(log n)
  4. D. O(i)

Correct answer: A. O(1)

Array elements sit in contiguous memory, so the address is base + i × size and is computed in constant time. O(i) would be the cost of reaching the i-th node of a linked list, not an array.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic