算法学习之“Big Oh Notation”
一、Asymptotic analysis
Suppose we are considering two algorithms, A and B, for solving a given problem. Furthermore, let us say that we have done a careful analysis of the running times of each of the algorithms and determined them to be and , respectively, where n is a measure of the problem size. Then it should be a fairly simple matter to compare the two functions and to determine which algorithm is the best!
这段话的意识,比较两种算法的时间成本来判定哪种算法更好。但实际应用中,T(n)是随着问题的规模n变化的,在事先不知道n的情况下,没法比较两种算法的优劣。由此,引入“Asymptotic behavior”,比较两种算法的T(n)在n比较大时的“增长级数”,例如:对数增长、线性增长、指数级增长。
二、Big Oh notation
In 1892, P. Bachmann invented a notation for characterizing the asymptotic behavior of functions. His invention has come to be known as big oh notation:
Definition (Big Oh)Consider a function f(n) which is non-negative for all integers . We say that ``f(n) is big oh g(n),'' which we write f(n)=O(g(n)), if there exists an integer and a constant c>0 such that for all integers , .
保罗.巴赫曼的“大O标记法”是最常用的一种算法 “Asymptotic behavior”的分析法(Asymptotic analysis)。它表示的是一种算法“Asymptotic behavior”的上界(upper bound)。
从定义可以看出,使用Big Oh Notation的过程中,需要求解这3个量:起始点(n0)、倍数(c)和基准函数。关于基准函数,我们一般可以选取简单的对数函数、线性函数等,一个个去套,哪个更合适就用哪个。
除了定义外,Big Oh Notation还有3个数学特性:和(summation)、积(product)以及传递性。
- What can we say about the asymptotic behavior of the sum of and ? (Theorems and ).
- What can we say about the asymptotic behavior of the product of and ? (Theorems and ).
- How are and related when ? (Theorem ).
1,通过Big Oh Notation的和性质(summation),可以简化多项式的的上界;
2,通过Big Oh Notation的积性质(product),可以直接求出两个多项式相乘后的上界;
3,通过Big Oh Notation的的传递性,一般与和结合使用;
4,多项式的Big Oh Notation,由最高次幂项,其中它的系数要大于0。
In fact, whenever we have a function, which is a polynomial in n, we will immediately ``drop'' the less significant terms (i.e., terms involving powers of n which are less than m), as well as the leading coefficient, , to write .
5,以10为底的对数的Big Oh Notation,参考点击打开链接
三、Tight Big Oh bound
Definition (Tightness) Consider a function f(n)=O(g(n)). If for every function h(n) such that f(n)=O(h(n)) it is also true that g(n)=O(h(n)), then we say that g(n) is a tight asymptotic bound onf(n).
Certain conventions have evolved which concern how big oh expressions are normally written:
- First, it is common practice when writing big oh expressions to drop all but the most significant terms. Thus, instead of we simply write .
- Second, it is common practice to drop constant coefficients. Thus, instead of , we simply write . As a special case of this rule, if the function is a constant, instead of, say O(1024), we simply write O(1).
Of course, in order for a particular big oh expression to be the most useful, we prefer to find a tight asymptotic bound (see Definition ). For example, while it is not wrong to write , we prefer to write f(n)=O(n), which is a tight bound.
以上是关于Big Oh Notation的一些约定。同时,学术界也给一些常用的Big Oh expression进行了特意命名,参考点击打开链接
算法学习之“Big Oh Notation”相关推荐
- 拿下斯坦福和剑桥双offer,00后的算法学习之路
董文馨,00后,精通英语,西班牙语.斯坦福大学计算机系和剑桥大学双Offer,秋季将进入斯坦福大学学习. 10岁开始在国外上学:12岁学Scratch: 13岁学HTML & CSS: 14岁 ...
- 好久没有看到这么有建设性德文章,由衷地赞叹《知其所以然地学习(以算法学习为例)》-By 刘未鹏(pongba)
知其所以然地学习(以算法学习为例) By 刘未鹏(pongba) C++的罗浮宫(http://blog.csdn.net/pongba) Updated(2008-7-24):更新见正文部分,有标注 ...
- 原创 | 初学者友好!最全算法学习资源汇总(附链接)
在计算机发展飞速的今天,也许有人会问,"今天计算机这么快,算法还重要吗?"其实永远不会有太快的计算机,因为我们总会想出新的应用.虽然在摩尔定律的作用下,计算机的计算能力每年都在飞快 ...
- 基本算法学习(一)之希尔排序(JS)
参考书: 严蔚敏-数据结构 希尔排序(Shell's Sort) 希尔排序又称"缩小增量排序",归属于插入排序一类,简单来说,和我们的插入排序比,它更快. 奇妙的记忆点: 内排序( ...
- 大顶堆删除最大值_算法学习笔记(47): 二叉堆
堆(Heap)是一类数据结构,它们拥有树状结构,且能够保证父节点比子节点大(或小).当根节点保存堆中最大值时,称为大根堆:反之,则称为小根堆. 二叉堆(Binary Heap)是最简单.常用的堆,是一 ...
- Surf算法学习心得(一)——算法原理
Surf算法学习心得(一)--算法原理 写在前面的话: Surf算法是对Sift算法的一种改进,主要是在算法的执行效率上,比Sift算法来讲运行更快!由于我也是初学者,刚刚才开始研究这个算法,然而网上 ...
- 算法学习:后缀自动机
[前置知识] AC自动机(没有什么关联,但是看懂了会对后缀自动机有不同的理解) [解决问题] 各种子串的问题 [算法学习] 学习后缀自动机的过程中,看到了许多相关性质和证明,但是奈何才疏学浅(lan) ...
- 算法学习:后缀数组 height的求取
[前置知识] 后缀数组 [定义] [LCP]全名最长公共前缀,两个后缀之间的最长前缀,以下我们定义 lcp ( i , j ) 的意义是后缀 i 和 j 的最长前缀 [z函数] 函数z [ i ] 表 ...
- 算法学习:最小圆覆盖
[参考博客] https://www.cnblogs.com/bztMinamoto/p/10698920.html [定义] [圆]一个圆心和他的半径,就能够确定这个半径 [解决问题] 字面意思 给 ...
最新文章
- web.py做图片上传网页
- 简化 MongoDB 关联运算
- css3实现宽度渐变
- YOLOX——Win10下训练自定义VOC数据集
- python中整数类型有—3_Python3 基本数据类型(3)
- php 当我添加数据成功后跳到首页 为什么刷新还会增加数据,使用post提交数据之后,有错误,页面刷新之后,想保持原有值...
- 很多人认为,因为我们是平民,做生意试不了错,输不起,试错成本太高
- java调用geckofx_Scala学习(三)数组相关操作
- 20172324 2018-2019-1 《程序设计与数据结构》第三周学习总结
- shell unzip,zip
- SkeyePlayer RTSP/RTMP低延迟播放器源码解析系列之效率优化方案
- android 开源项目收集
- webstorm设置黑色背景
- ImageIO类说明
- 天池广东工业智造大数据创新大赛--铝型材表面瑕疵识别 --top1方案
- 大数据与云计算技术---(一)hadoop大数据平台
- 安卓手机获取IP地址
- 初见物理引擎库Cannon.js:使用dat.gui修改物体属性
- (转)Google Voice呼转到中国电话的五种方法
- python控件获取焦点_PyQt控件键盘焦点