简体   繁体   English

n log n是O(n)?

[英]n log n is O(n)?

I am trying to solve this recurrence 我试图解决这种情况

T(n) = 3 T(n/2) + n lg n .. T(n)= 3 T(n / 2)+ n lg n ..

I have come to the solution that it belongs to masters theorem case 2 since n lg n is O(n^2) 我已经得出它属于主要定理案例2的解决方案,因为n lg n是O(n ^ 2)

but after referring to the solution manual i noticed this solution that they have 但在参考解决方案手册后,我注意到他们有这个解决方案

在此输入图像描述

The soluttion says that n lg n = O ( n ^(lg 3 - e)) for e between 0 and 0.58 解决方案说,对于0到0.58之间的e,n lg n = O(n ^(lg 3 - e))

so this means n lg n is O(n) .. is this right? 所以这意味着n lg n是O(n)..这是对的吗? Am i missing something here? 我错过了什么吗?

Isn't nlgn O(n^2) ? 不是nlgn O(n ^ 2)?

This will explain things better 这将更好地解释事情 在此输入图像描述

n*log(n) is not O(n^2) . n*log(n)不是O(n^2) It's known as quasi-linear and it grows much slower than O(n^2) . 它被称为准线性,它比O(n^2)生长得慢得多。 In fact n*log(n) is less than polynomial. 实际上n*log(n)小于多项式。

In other words: 换一种说法:

O(n*log(n)) < O(n^k)

where k > 1 其中k > 1

In your example: 在你的例子中:

3*T(2n) -> O(n^1.585)

Since O(n^1.585) is polynomial and dominates O(n*log(n)) , the latter term drops off so the final complexity is just O(n^1.585) . 由于O(n^1.585)是多项式并且支配O(n*log(n)) ,后一项下降所以最终复杂度仅为O(n^1.585)

n lg3 is not O(n). n lg3不是O(n)。 It outgrows O(n)... In fact, any exponent on n that is larger than 1 results in an asymptotically longer time than O(n). 它超过了O(n)......实际上,n上任何大于1的指数都会导致渐近时间比O(n)更长。 Since lg(3) is about 1.58, as long as you subtract less than .58 from the exponent it is asymptotically greater than O(n). 由于lg(3)约为1.58,只要从指数中减去小于.58,它就渐近地大于O(n)。

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

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