What is the time complexity of traversing all N elements of an array once?

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

If an algorithm visits each of the N elements exactly once, its running time is O(N), commonly called linear time. For example, a loop from index 0 through Nāˆ’1 performs approximately N iterations. Constants and lower-order terms are ignored in asymptotic analysis. Thus, 2N + 5, 10N, and N + 100 are all O(N), although their actual execution times may differ.