python内置函数的时间复杂性``all()''
如何知道python内置功能的时间复杂性all()
?
我尝试了这些方式,但没有找到答案。
- 搜索了官方复杂性文档,但没有找到答案。
- 试图在Python源代码中找到。但是我找不到算法
all()
的位置。这是我发现的唯一关于all()
的文件。 在此处输入图像描述
How to know the time complexity of Python built-in Function all()
?
I have tried these ways but found no answer.
- searched on official complexity documentation, but found no answer.
- Tried to find in Python source code. But I cannot find where the algorithm
all()
. This is the only file aboutall()
I found.
enter image description here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
定义上
o(n)
。它必须检查提供的所有值的真实性,直到找到虚假的价值为止。它短路(如果找到一个虚假的值,它会立即停止并返回false
而无需检查输入的其余部分),因此在许多情况下,它不会完成所有工作,但是如果实际上,输入是所有真理,根据定义,必须检查所有输入,进行o(n)
工作。 Big-O不在乎短路的可能性。Definitionally
O(n)
. It has to check the truthiness of all the values provided until it finds a falsy value. It short-circuits (if it finds a single falsy value, it stops immediately and returnsFalse
without checking the rest of the input), so in many cases it won't do all the work, but if the input is in fact all truthy, it must, by definition, check all of them, doingO(n)
work. Big-O doesn't care about the possibility of short-circuiting.