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

最新文章

  1. html5 历史管理onhashchange和state
  2. 关于jQuery外部框架
  3. ADB 常用命令总结(持续更新)
  4. 【LeetCode OJ】Valid Palindrome
  5. Codeforces Round #306 (Div. 2) D. Regular Bridge 构造
  6. 通过redis-rdb-tools分析redis内存使用量
  7. 基于visual Studio2013解决C语言竞赛题之1036递归求值
  8. 一次失败的刷题经历:[LeetCode]292之尼姆游戏(Nim Game)(转)
  9. python数据挖掘_Json结构分析
  10. bzoj 4008: [HNOI2015]亚瑟王
  11. ACM Wooden Stricks
  12. supervisor支持python虚拟环境venv
  13. j假设程序需要要一个int烈血的刀变量来保存1英里所包含的步数(5280)为该变量编写一条声明语句。
  14. HTML自动跳转
  15. 简单理解Linux的Loopback接口
  16. Django项目----快速实现增删改查组件(起步阶段!!!)
  17. 异步编程之asyncio简单介绍
  18. spring+spring mvc+JdbcTemplate 入门小例子
  19. learngin uboot design parameter recovery mechanism
  20. mysql5.5以上开启慢查询

热门文章

  1. RTX与SVN使用手册适用于新手
  2. Viewpager模仿微信主布局的三种方式 ViewPager,Fragment,ViewPager+FragmentPagerAdapter
  3. Android WebView使用深入浅出
  4. 如何优雅的写一篇安利文-以Sugar ORM为例
  5. OOP多态和继承要点
  6. jQuery问题:$XXX is not a function
  7. 实施项目--.NET实现仓库看板的一些感想
  8. lei
  9. linux中的数值运算
  10. HTML布局篇之双飞翼(圣杯)布局