AmortizedAnalysis

# AmortizedAnalysis - Amortized Algorithm Analysis There are...

This preview shows pages 1–2. Sign up to view the full content.

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 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.

{[ snackBarMessage ]}

### Page1 / 6

AmortizedAnalysis - Amortized Algorithm Analysis There are...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online