简体   繁体   English

是 2^(log n) = O(log(n)) 吗?

[英]Is 2^(log n) = O(log(n))?

Are these two equal?这两个相等吗? I read somewhere that O(2lg n) = O(n).我在某处读到 O(2lg n) = O(n)。 Going by this observation, I'm guessing the answer would be no, but I'm not entirely sure.根据这一观察,我猜答案是否定的,但我并不完全确定。 I'd appreciate any help.我很感激任何帮助。

Firstly, O(2log(n)) isn't equal to O(n) .首先, O(2log(n))不等于O(n)

To use big O notation, you would find a function that represents the complexity of your algorithm, then you would find the term in that function with the largest growth rate.要使用大 O 表示法,您会找到一个表示算法复杂性的函数,然后您会在该函数中找到增长率最大的项。 Finally, you would eliminate any constant factors you could.最后,您可以消除任何可能的常数因素。

eg say your algorithm iterates 4n^2 + 5n + 1 times, where n is the size of the input.例如,假设您的算法迭代4n^2 + 5n + 1次,其中 n 是输入的大小。 First, you would take the term with the highest growth rate, in this case 4n^2 , then remove any constant factors, leaving O(n^2) complexity.首先,您将采用增长率最高的术语,在本例中为4n^2 ,然后删除任何常数因子,留下O(n^2)复杂度。

In your example, O(2log(n)) can be simplified to O(log(n))在您的示例中, O(2log(n))可以简化为O(log(n))

Now on to your question.现在回答你的问题。

In computer science, unless specified otherwise, you can generally assume that log(n) actually means the log of n, base 2.在计算机科学中,除非另有说明,否则通常可以假设log(n)实际上表示 n 的对数,以 2 为底。

This means, using log laws, 2^log(n) can be simplified to O(n)这意味着,使用对数定律, 2^log(n)可以简化为O(n)

Proof:证明:

y = 2^log(n)
log(y) = log(2^log(n))
log(y) = log(n) * log(2) [Log(2) = 1 since we are talking about base 2 here]
log(y) = log(n)
y = n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM