gpt4 book ai didi

algorithm - 这个空间复杂度在这个级数和中是如何计算的?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:46:11 27 4
gpt4 key购买 nike

谁能给我解释一下下面的空间复杂度计算?

Given a stream of numbers of size b bits, calculate the sum of these numbers.

If we have seen T numbers so far, the sum is at most T2^b and hence needs at most O(b+log T) space.

现在,T2^b 必须是上限,因为更准确的上限是 T(2^b - 1)。

但是他们是如何计算出空间上界是O(b +logT)的呢?

最佳答案

使用 m 位,您可以存储最多(大约)2m 的数字。因此,换句话说,如果您知道总和,则需要取对数以获得位数(以及空间复杂度)。

在这里,log(T 2b) = b + log(T)

关于algorithm - 这个空间复杂度在这个级数和中是如何计算的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34939923/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com