Big O 是否可能小于 O(1)?
可能的重复:
有 O(1/n) 算法吗?
是否有可能你的代码是 Big O 小于 O(1) 吗?
Possible Duplicate:
are there any O(1/n) algorithms?
Is it ever possible for your code to be Big O less than O(1)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
并不真地。
O(1)
是常数时间。 无论您将其表示为O(1)
或O(2)
还是O(.5)
,就纯粹的大而言,实际上没有什么区别O 表示法。正如这个问题中所述,技术上可以有一个
O(1/n)
,但现实世界中没有任何有用的算法可以满足这一点(尽管有些算法确实将1/n
作为其算法复杂性的一部分)。Not really.
O(1)
is constant time. Whether you express that asO(1)
orO(2)
orO(.5)
really makes little difference as far as purely big O notation goes.As noted in this question, it is technically possible to have an
O(1/n)
, but that no real-world useful algorithm would satisfy this (though some do algorithm's do have1/n
as part of their algorithmic complexity).O(1) 简单地说就是常数时间操作。 该时间可以是 1 纳秒或 100 万年,该符号不是绝对时间的度量。 当然,除非您在时间机器的操作系统上工作,否则您的 DoTimeTravel( ) 函数可能具有 O(-1) 复杂度:-)
O(1) simply means a constant time operation. That time could be 1 nanosecond or 1 million years, the notation is not a measure of absolute time. Unless of course you are working on the OS for a time machine, than perhaps your DoTimeTravel( ) function would have O(-1) complexity :-)
唯一花费少于 O(1)(恒定时间)的事情是一个完全不执行任何操作的操作,因此花费的时间为零。 但即使是 NOP 通常也需要固定数量的周期......
The only thing that would take less than O(1) (constant time) would be an operation that did absolutely nothing, and thus took zero time. But even a NOP usually takes a fixed number of cycles...