- Normally when we analyze algorithm, we look into worst case of individual operations
- Sometime, looking at worst case may be too severe
- We may want to know total worst case for sequence of operations
- We only resize every so often
- Many O(1) operations are followed by O(N) operation
- What is total cost of inserting many elements?
Amortized cost = Cost (n operation)/n
- For mission critical application, don't use dynamic resizable array
- Python
List
is underhood array.
- Shrink when 25% of array is full
- In this case; drop the half
- Still after dropping, half of array will still be empty