This is regarding amortized analysis. Following is text from an article.
Amortized analyis for problems in which one must perform a series of
operations, and our goal is to analyze the time per operation. The
motivation for amortized analysis is that looking at the worst case
time per operation can be too pessimistic if the only way to produce
an expensive is to “set it up” with a a large number of cheap
operations before hand.
Question: What does author mean by last statement i.e., “if the only way to produce an expensive is to “set it up” with a a large number of cheap operations before
hand”? Can any one please explain with example what this statement mean?
Thanks!
Another example. Consider an array that dynamically increases it’s capacity when an element is added that exceeds the current capacity. Let increasing the capacity be O(n), where n is the old size of the array. Now, adding an element has a worst case complexity of O(n), because we might have to increase the capacity. The idea behind amortized analysis is that you have to do n simple adds that cost O(1) before the capacity is exhausted. Thus, many cheap operations lead up to one expensive operation. In other words, the expensive operation is amortized by the cheap operations.