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

Insertion at the beginning of an array usually requires existing elements to be shifted one position to the right to create space. If the array contains n elements, as many as n elements may need to be moved. Therefore, the worst-case time complexity is O(n). This differs from accessing an element by index, which is O(1). Understanding the difference between access and modification complexity is important when comparing arrays with linked lists.