Which statement about inserting at the beginning of an array is true?

Prepare for the TJR Bootcamp Test with flashcards and detailed questions. Get hints and explanations for each query. Ace your exam!

Multiple Choice

Which statement about inserting at the beginning of an array is true?

Inserting at the beginning of an array requires moving every existing element one position to the right to make room for the new item. That means you touch all n elements already in the array, so the work grows linearly with n. Hence the time complexity is O(n).

Even if the array has extra capacity, that doesn't help this operation, because you still must shift each existing element to its new position. That’s why this isn’t O(1) or O(1) amortized, and it isn’t O(log n) either. The statement that it’s O(n) due to shifting is the correct one.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy