• [名词解释]Constant Amortized Time


    http://stackoverflow.com/questions/200384/constant-amortized-time

    分摊常量时间:

    Amortised time explained in simple terms:

    If you do an operation say a million times, you don't really care about the worst-case or the best-case of that operation - what you care about is how much time is taken in total when you repeat the operation a million times.

    So it doesn't matter if the operation is very slow once in a while, as long as "once in a while" is rare enough for the slowness to be diluted away. Essentially amortised time means "average time taken per operation, if you do many operations". Amortised time doesn't have to be constant; you can have linear and logarithmic amortised time or whatever else.

    Let's take mats' example of a dynamic array, to which you repeatedly add new items. Normally adding an item takes constant time (that is, O(1)). But each time the array is full, you allocate twice as much space, copy your data into the new region, and free the old space. Assuming allocates and frees run in constant time, this enlargement process takes O(n) time where n is the current size of the array.

    So each time you enlarge, you take about twice as much time as the last enlarge. But you've also waited twice as long before doing it! The cost of each enlargement can thus be "spread out" among the insertions. This means that in the long term, the total time taken for adding m items to the array is O(m), and so the amortised time (i.e. time per insertion) is O(1).

  • 相关阅读:
    实战练习6—水波纹制作
    实战练习5—冰块中的效果
    实战练习4—逼真眼泪
    5、选择工具&描边
    实战练习3-修饰服装皱褶
    实战练习2—方块
    实战练习1—照片的局部放大
    23、裁剪
    iOS 处理第三方SDK冲突问题
    iOS 修改启动图无效
  • 原文地址:https://www.cnblogs.com/diegodu/p/3806437.html
Copyright © 2020-2023  润新知