Difference between average case and amortized analysis

后端 未结 3 1946
無奈伤痛
無奈伤痛 2020-12-04 10:05

I am reading an article on amortized analysis of algorithms. The following is a text snippet.

Amortized analysis is similar to average-case analysis i

3条回答
  •  粉色の甜心
    2020-12-04 10:56

    Average case analysis makes assumptions about the input that may not be met in certain cases. Therefore, if your input is not random, in the worst case the actual performace of an algorithm may be much slower than the average case.

    Amortized analysis makes no such assumptions, but it considers the total performance of a sequence of operations instead of just one operation.

    Dynamic array insertion provides a simple example of amortized analysis. One algorithm is to allocate a fixed size array, and as new elements are inserted, allocate a fixed size array of double the old length when necessary. In the worst case a insertion can require time proportional to the length of the entire list, so in the worst case insertion is an O(n) operation. However, you can guarantee that such a worst case is infrequent, so insertion is an O(1) operation using amortized analysis. Amortized analysis holds no matter what the input is.

提交回复
热议问题