O 表示法,O(∞) = O(1)?
这么一想;有人会说 O(∞) 实际上是 O(1) 吗?
- 我的意思是它不取决于输入大小?
- 所以在某种程度上它是恒定的,尽管它是无限的。
或者是唯一“正确”的表达方式 O(∞)?
So a quick thought; Could one argue that O(∞) is actually O(1)?
- I mean it isn't depend on input size?
- So in some way its, constant, even though it infinity.
Or is the only 'correct' way to express it O(∞)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你的论点不太正确。
大 O 表示法忽略常量倍数;
O(1)
和O(42)
之间没有区别,或者O(log(n))
和O( 3π log(n)) 。
标准约定是不使用任何常数倍数。
然而,
O(∞)
意味着一种永远终止的“算法”,而不是O(1)
,它会在某个时刻终止。Your argument is not quite correct.
Big O notation disregards constant multiples; there's no difference between
O(1)
andO(42)
, or betweenO(log(n))
andO(3π log(n))
.Standard convention is to not use any constant multiples.
However,
O(∞)
would mean an “algorithm” that never terminates, as opposed toO(1)
which will terminate at some point.回答这个问题:
否
主要区别在于 O(1) 将在某个时刻结束,而 O(∞) 永远不会结束。
它们都不包含变量,但具有不同的含义:
O(1)
(或 O(121) 或 O(无论什么,但不是无穷大):独立于函数参数,但以< code>O(∞) :独立于函数参数,并且非结尾
正如另一个答案中指出的那样,无穷大实际上并不在大 O 表示法的范围内,但简单的“不”仍然存在当然,O(1) 和 O(∞) 并不相同。
To answer the question :
No
The main difference is that O(1) will end at some point, while O(∞) never ends.
They both don't include a variable, but have both different meanings :
O(1)
(or O(121) or O(whatever but not infinity) : independendent of the functions arguments, but endingO(∞)
: independendent of the functions arguments, and non endingAs pointed out in another answer, infinity isn't really in the domain of the big-O notation, but the simple 'no' than remains of course, O(1) and O(∞) are not the same.
Big-Oh 是衡量所需资源如何随着 N 增加而扩展的指标。 O(5 小时) 和 O(5 秒) 都是 O(1),因为随着 N 的增加不需要额外的资源。
Big-Oh is a measure of how something the resources required scales as N increases. O(5 hours) and O(5 seconds) are both O(1) since no extra resources are needed as N increases.
无穷大不是数字,或者至少不是实数,因此表达式格式错误。表达这一点的正确方法是简单地声明程序不会终止。注意:程序,而不是算法,因为算法一定会终止。
(如果您愿意,您也许可以在超限数上定义大 O 表示法。不过,我不确定这是否有任何用处。)
Infinity is not a number, or at least not a real number, so the expression is malformed. The correct way to express this is to simply state that a program doesn't terminate. Note: program, not algorithm, as an algorithm is guaranteed to terminate.
(If you wanted, you might be able to define big-O notation on transfinite numbers. I'm not sure if that would be of any use, though.)