算法中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.
算法中Amortised time的理解的更多相关文章
- KMP算法中next函数的理解
首先要感谢http://blog.csdn.net/v_july_v/article/details/7041827以及http://blog.chinaunix.net/uid-27164517-i ...
- KMP算法中next数组的理解与算法的实现(java语言)
KMP 算法我们有写好的函数帮我们计算 Next 数组的值和 Nextval 数组的值,但是如果是考试,那就只能自己来手算这两个数组了,这里分享一下我的计算方法吧. 计算前缀 Next[i] 的值: ...
- KMP算法中我对获取next数组的理解
之前在学KMP算法时一直理解不了获取next数组的函数是如何实现的,现在大概知道怎么一回事了,记录一下我对获取next数组的理解. KMP算法实现的原理就不再赘述了,先上KMP代码: 1 void g ...
- 理解KNN算法中的k值-knn算法中的k到底指的是什么 ?
2019-11-09 20:11:26为方便自己收藏学习,转载博文from:https://blog.csdn.net/llhwx/article/details/102652798 knn算法是指对 ...
- 问题 1690: 算法4-7:KMP算法中的模式串移动数组
题目链接:https://www.dotcpp.com/oj/problem1690.html 题目描述 字符串的子串定位称为模式匹配,模式匹配可以有多种方法.简单的算法可以使用两重嵌套循环,时间复杂 ...
- 机器学习算法中的准确率(Precision)、召回率(Recall)、F值(F-Measure)
摘要: 数据挖掘.机器学习和推荐系统中的评测指标—准确率(Precision).召回率(Recall).F值(F-Measure)简介. 引言: 在机器学习.数据挖掘.推荐系统完成建模之后,需要对模型 ...
- java中线程同步的理解(非常通俗易懂)
转载至:https://blog.csdn.net/u012179540/article/details/40685207 Java中线程同步的理解 我们可以在计算机上运行各种计算机软件程序.每一个运 ...
- 动态规划(Dynamic Programming)算法与LC实例的理解
动态规划(Dynamic Programming)算法与LC实例的理解 希望通过写下来自己学习历程的方式帮助自己加深对知识的理解,也帮助其他人更好地学习,少走弯路.也欢迎大家来给我的Github的Le ...
- 关于diffing算法中key的使用
在vue和react中(只学了这两个),经常需要渲染元素到DOM上,而且如果不写key,有的浏览器会进行报错或者进行提示. 在我的理解里:key其实就是一个身份的标识,证明这个位置坐的就是这个人.后期 ...
随机推荐
- python 抓取拉勾网 攻略
废话不多说,直接上代码,将数据存入Mongdb import requests import pymongo import time import random mycon = pymongo.Mon ...
- vue 中 @click.native.prevent 事件
在项目中看到@click.native.prevent, 查了一点资料 总结一下, 1.给vue组件绑定事件时候,必须加上native ,否则会认为监听的是来自Item组件自定义的事件, 2.prev ...
- 判断浏览器类型JS
// 判断浏览器类型 getExplorer() { var explorer = window.navigator.userAgent, compare = function (s) { retur ...
- redis常见问题和解决方案
转载:https://www.cnblogs.com/aspirant/p/6820262.html [原创]那些年用过的Redis集群架构(含面试解析) redis常见问题和解决方案 持久化.主从问 ...
- Coco56公众号关键字索引
目录 1. 本文地址 2. 公众号介绍 3. 关键词及含义 1. 本文地址 博客园:https://www.cnblogs.com/coco56/p/11182421.html 简书:https:// ...
- PIL 中的 Image 模块
转载:http://www.cnblogs.com/way_testlife/archive/2011/04/20/2022997.html PIL 中的 Image 模块 本文是节选自 PIL ...
- LaunchScreen 设置启动图片出现的问题
更换启动图片的时候出现了一系列的小问题,让人头疼,怀疑人生. 1.更换了图片,显示还是老的图片! -->重启手机,clean Xcode 2.设置布局的时候,请务必要这么布局,很完美! 如果你 ...
- jpa 自定义sql 删除方法注意点
1.jpa自带的delete()方法可以成功删除对象 delete(id),或者delete(entity) 2.自定义删除方法注意点 参考:https://www.jianshu.com/p/9d5 ...
- TCP/IP基础总结性学习(2)
简单的HTTP协议 一.HTTP 协议用于客户端和服务器端之间的通信 客户端和服务器的定义:请求访问文本或图像等资源的一端称为客户端,而提供资源响应的一 端称为服务器端.在两台计算机之间使用 HTTP ...
- Zookeeper安装使用--单机模式
1.version package准备 zookeeper-3.4.5.tar.gz 2.mkdir zookeeper folder.tar the package mkdir zookeeper ...