算法中Amortised time的理解

ref: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).

---------------------------------

ref: http://stackoverflow.com/questions/19650636/amortized-analysis

Expected time:

We make some assumptions and, based on these assumptions, we make statements about the running time.

Hash tables is one such example. We assume that the data is well-distributed, and claim that the running time of operations are O(1), whereas the worst-case running time for an operation is actually O(n).

Amortized time:

Even though one operation may take longer than some given time, the time across multiple operations will balance out to give the mentioned running time.

(Well-implemented) self-resizing arrays is one such example. When you insert, it takes O(n) to resize the array, but, across many inserts, each will take O(1) on average.

posted on 2014-06-06 11:26 过雁 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/zwCHAN/p/3772246.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"Average Time"是指在进行多个操作时,每个操作所花费的平均时间。它与响应时间的变动趋势有关。如果操作的响应时间变动较大,使用平均时间来衡量可能不够准确。举个例子,假设有三个操作的时间分别为1秒、5秒和12秒,则平均时间为6秒。而另一种情况下,操作的时间分别为5秒、6秒和7秒,平均时间仍然为6秒,尽管第二种情况相对于第一种情况更加稳定。因此,"Average Time"并不代表稳定的时间,它更多地是指在进行多次操作时的平均时间。这个概念可以应用于线性时间、对数时间等不同的情况。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [算法Amortised time理解](https://blog.csdn.net/weixin_30808575/article/details/97672586)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [loadrunner_analysis技巧_average 和 90% percent](https://blog.csdn.net/weixin_34253539/article/details/85615297)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值