What is the amortized time complexity of the 'push' operation for a dynamic array that doubles in size when full?
Show answer
O(1)
While a single push might trigger a resize costing O(n), the total cost of n pushes is O(n) because resizing happens infrequently. Using the aggregate method, the average cost per operation is constant.
Also asked as:
- For a dynamic array that doubles in size when full, what is the amortized time complexity of adding an element via 'push'?