Algorithms and Data Structures · Junior · Question 63 of 75

What does "amortized O(1)" mean for arr.push?

Explanation

When the internal buffer is full, the array allocates a bigger one (usually about double) and copies everything. Because the size doubles, these copies are rare, and the total cost of n pushes is O(n).

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 63

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz