Big O Gym › Problem

Big O Quiz: Dynamic Array Append

What is the amortized time complexity of appending to a dynamic array (e.g. Python list, JavaScript Array)?

Concept: amortized analysis

Most appends are constant-time writes to an internal buffer. Occasionally the buffer fills and the array doubles, copying all existing elements - that single append is O(n). But because the buffer doubles, those expensive appends are rare enough that the **amortized** cost across `n` appends is bounded by 2n total writes - **O(1) amortized per append**. The worst-case-per-append is O(n); make sure the question is asking for amortized when you give this answer.

More Big O practice problems · Today's daily problem