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 n1 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 nk
add operations. BUT, the maximum running time of all the
clears is the total number of elements that get cleared, which is
nk. Thus, the maximum running time of n operations is 2(nk)
≤
2n. Thus the average time for an operation in a clearable
table is less than 2n/n = 2. Thus, even though the worstcase
time for a clear operation is O(n), the amortized worstcase
time of add and clear operations over n operations is O(1).
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '09
 Computer Science, Operations, operation, Analysis of algorithms, total number, worst case

Click to edit the document details