Introduction to Amortized Analysis
- Amortized analysis evaluates the average cost per operation over a sequence of operations, rather than a single operation in isolation
This is relevant because some operations are usually fast, but have rare occurrences where they are slow
- e.g. appending to a dynamic array:
- Most inserts are
- But if the array runs out of space, it takes time → worst case
- The entire array needs to be reallocated
- Over many appends, the time complexity of this operation is
Amortized Analysis of Doubling Strategy
- Method of increasing array size by doubling size every time it is full
- Using amortized analysis, the total work is equal to:
- This leads to total work being → efficient method
Amortized Analysis of Multi-delete Stack
- A multi-delete stack has additional operation delete the top elements from the stack
- We would think it has time complexity of , but this is not true
- It is actually amortized per operation
- Each pop must correspond to a previous push
- At most pushes → cost =
- Total pops total pushes → cost =
- Amortized cost per operation: