Amortized Algorithm Analysis
There are some operations that have “costly” running times,
but the worst possible average running time of the same
operation over a sequence of several operations is much less
“costly.” In these situations, we say that the
amortized
worst-
case running time of the operation is the latter value. This
claim is a stronger claim, or more accurate analysis of an
operation than just finding it’s worst case running time for a
single operation.
Consider the clearable table data structure, that supports two
operations:
1) Add an entry.
2) Clear the entire table.
An add operation always takes O(1) time. A clear operation
takes O(k) time where there are k items currently in the table.
Starting with an empty table, when we run n operations, it is
possible that a single clear operation is
Ω
(n), since the table
could have up to n-1 items in it. Now, let’s do the amortized
analysis:
Our operations can be categorized as a sequence of several
adds followed by a clear repeated several times. If there are k
clear operations out of n total operations, then there are n-k
add operations. BUT, the maximum running time of all the
clears is the total number of elements that get cleared, which is
n-k. Thus, the maximum running time of n operations is 2(n-k)
≤
2n. Thus the average time for an operation in a clearable
table is less than 2n/n = 2. Thus, even though the worst-case
time for a clear operation is O(n), the amortized worst-case
time of add and clear operations over n operations is O(1).

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
This is the end of the preview. Sign up
to
access the rest of the document.