对数算法的 Big-oh 复杂度

发布于 2024-09-06 08:14:08 字数 256 浏览 6 评论 0原文

我在计算 Big-oh 复杂度时遇到的问题很少。由于日志库操作,有两个问题我无法解决。这里有两个问题:

n = 正在操作的数据项数量

1) n^3 + n^2 log (base 2) n + n^3 log (base 2) n

2) 2n^3 + 1000n^2 + log (base 4) n + 300000n

当日志有基数时我很困惑。您如何计算这些的复杂性?如果可能的话,有人愿意解释一下如何用一些细节来解释复杂性吗?

Few more problems I ran into calculating the Big-oh complexity. There are 2 problems which I cannot solve due to log base operations. Here are the two problems:

n = # of data items being manipulated

1) n^3 + n^2 log (base 2) n + n^3 log (base 2) n

2) 2n^3 + 1000n^2 + log (base 4) n + 300000n

I am confused when the logs have a base number. How do you go about calculating the complexity for these? Anyone care to explain how you get the complexity with a bit of detail if possible?

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

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

发布评论

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

评论(3

是伱的 2024-09-13 08:14:08

对数的底是无关紧要的。你可以忽略它。因此:

1) 它是O(n^3 log n),因为这是增长最快的项。

2) 出于同样的原因,它是O(n^3)

底数是无关紧要的,因为对数底数 a (x) = 对数底数 b (x) / 对数底数 b (a),因此任何对数都与另一个对数相差一个常数。

我建议您在此处阅读有关对数属性的更多信息。

The base of the logarithm is irrelevant. You can just ignore it. Therefore:

1) It's O(n^3 log n) because that's the term that grows the fastest.

2) It's O(n^3) for the same reason.

The base is irrelevant because log base a (x) = log base b (x) / log base b (a), so any logarithm differs from another by a constant.

I suggest you read more about the properties of the logarithm here.

拒绝两难 2024-09-13 08:14:08

您不需要“计算基数的复杂性”,只需将其增长率与其他项的增长率进行比较(请参阅此对数增长率图,给您一个想法)

请注意,要解决这些问题,您不需要关注对数的基数。

O(x + y + z) === O(max(x,y,z))

因此,决定哪一项的总和最大,您就可以解决您的问题。

You don't need to "calculate complexity for a base number", you can just compare its growth rate to that of the other terms (see this graph of logarithm growth rates, to give you an idea )

Note that to solve these problems, you don't need to pay attention to the base of the logs.

O(x + y + z) === O(max(x,y,z))

So, decide which of the summed terms is largest and you can solve your problems.

青衫负雪 2024-09-13 08:14:08

在渐进复杂度的计算中,假设n非常大,因此可以忽略常数。当你有一个总和时,只考虑最大的项。

在您的示例中,这会导致:

1) n^3 log(n)

2) n^3

In the calculation of asymptotic complexity, n is assumed to be very large and thus constants can be ignored. When you have a sum, only take into account the biggest term.

In your examples, this results in:

1) n^3 log(n)

2) n^3

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