python内置函数的时间复杂性``all()''

发布于 2025-01-29 17:02:14 字数 304 浏览 0 评论 0原文

如何知道python内置功能的时间复杂性all()

我尝试了这些方式,但没有找到答案。

  1. 搜索了官方复杂性文档,但没有找到答案。
  2. 试图在Python源代码中找到。但是我找不到算法all()的位置。这是我发现的唯一关于all()的文件。 在此处输入图像描述

How to know the time complexity of Python built-in Function all()?

I have tried these ways but found no answer.

  1. searched on official complexity documentation, but found no answer.
  2. Tried to find in Python source code. But I cannot find where the algorithm all(). This is the only file about all() I found.
    enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白日梦 2025-02-05 17:02:14

定义上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 returns False 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, doing O(n) work. Big-O doesn't care about the possibility of short-circuiting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文