【问题标题】:Time Complexity of array_filter in PHPPHP中array_filter的时间复杂度
【发布时间】:2012-10-07 12:08:44
【问题描述】:

假设我正在使用的回调函数的时间复杂度为 O(1),那么 PHP 中 array_filter function 的运行时间是多少,我是否可以在某个地方找到 array_filter 函数的实现?

谢谢

【问题讨论】:

    标签: php arrays time-complexity array-filter


    【解决方案1】:

    array_filter的来源在这里,C-f for array_filter: https://github.com/php/php-src/blob/master/ext/standard/array.c

    我找到了答案(它表明 array_filter 是 O(n),并非完全不明显,因为它需要对列表中的每个项目只迭代一次): List of Big-O for PHP functions

    【讨论】:

      【解决方案2】:

      复杂度应该是O(N)

      它只是循环它并使用回调来检查元素。

      您可以找到 the implementation here

      【讨论】:

        猜你喜欢
        • 2011-08-04
        • 1970-01-01
        • 2016-02-13
        • 2012-08-14
        • 2011-10-31
        • 2013-09-12
        • 2018-08-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多