As a simple example, in a specific implementation of the dynamic array, we double the size of the array each time it fills up.
Because of this, array reallocation may be required, and in the worst case an insertion may require O(n).
However, a sequence of n insertions can always be done in O(n) time, because the rest of the insertions are done in constant time, so n insertions can be completed in O(n) time.
The amortized time per operation is therefore O(n) / n = O(1).
--from Wiki
But in another book :Each doubling takes O(n) time, but happens so rarely that its amortized time is still O(1).
Hope somebody could tell me does the rare situation infer the Wiki explanation? Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…