What is the time complexity of traversing all elements of a one-dimensional array containing N elements?

Options

  • A. O(1)
  • B. O(log n)
  • C. O(n)
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. O(n)

Detailed Explanation

Correct Answer: C. O(n)

Explanation: Traversing an array requires visiting each of its N elements once.

  • One operation is performed for each element.
  • Total operations increase linearly with the number of elements.
  • Therefore, time complexity is O(n).