What is the worst-case time complexity of inserting an element at the beginning of an 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: Inserting an element at the beginning of an array generally requires shifting existing elements one position to the right.

  • All N existing elements may need to be shifted.
  • Therefore, worst-case time complexity is O(n).
  • Insertion at the end can be O(1) when spare capacity is available.