tags | |
---|---|
|
An amortized analysis is any strategy for analyzing a sequence of operations to show that the average cost per operation is small, even though a single operation within the sequence might be expensive. The probability is not involved in this calculation.
[!example]
How can we know how large a given data structure should be? We have to allocate enough memory for the program to not overflow, but minimizing its size. This is done using [[Dynamic tables]].
There are three common amortization arguments:
- aggregate method
- accounting method
- potential method
No method is best, and in the case of accounting and potential method different schemes may yield radically different bounds.
The [[Dynamic tables]] example is a case of the aggregate method and is, though simple, lacking in any kind of precision in respect to the other methods.
The idea is to charge the
Warning
The bank account must not be negative
Thus, the total amortized cost provides an upper bound on the total true cost. $$ \sum c_{i} \leq \sum \dot{c}_{i} $$
In the example of the [[Dynamic tables]] we can assume an amortized cost of $$3$ for the
- immediate insertion
- move a recent item
- move an old item
The idea of the potential method is very similar to the accounting method but the framework is:
- Initial data is
$D_{0}$ - Operation
$i$ transforms$D_{i-1}$ to$D_{i}$ with cost$c_{i}$ - Define a potential function
$\Phi:{ D_{i} } \to R$ such that$\Phi(D_{0}) = 0$ and$\Phi(D_{i}) \geq 0$ - The amortized cost is
$\dot{c_{i}} = c_{i} + \Phi D(i) - \Phi(D_{i-1})$
If