简体   繁体   English

O(N!* N)是可接受的大型复杂度类吗?还是我删除常数而只说O(N!)?

[英]Is O(N!*N) an acceptable big oh complexity class or do I remove the constant and just say O(N!)?

O(N!N)是可接受的大复杂度类吗?还是我删除常数而只说O(N!)?

See What is O(log(n!)) and O(n!) and Stirling Approximation , which discusses the relationship between O(n!) and O(n^n) . 请参阅什么是O(log(n!))和O(n!)和斯特林逼近 ,其中讨论了O(n!)O(n^n)之间的关系。 This should help you to determine the appropriate big-O when you multiply those by n . 当将它们乘以n时,这应该有助于您确定适当的big-O。

The additional n in your problem is not a constant, and is not dominated by the n! 问题中的附加n不是常数,也不由n! , so it does not disappear from the function when you convert from the actual value of the function to the Big-O (or Big-Theta) asymptotic complexity class of the function. ,因此当您从函数的实际值转换为函数的Big-O(或Big-Theta)渐近复杂度类时,它不会从函数中消失。

For Big-O, it's probably sufficient to say O(n^(n+1)) , but that's not sufficient for Big-Theta. 对于Big-O,说O(n^(n+1))可能就足够了,但是对于Big-Theta来说还不够。

Here's a related problem involving Big-O and factorials: https://math.stackexchange.com/questions/323290/stirlings-approximation 这是一个涉及Big-O和阶乘的相关问题: https : //math.stackexchange.com/questions/323290/stirlings-approximation

Lets do some algebra .... 让我们做一些代数..

  N!      =  N x (N - 1) x (N - 2) x ... 1    // by definition

  N! x N  =  N x (N x (N - 1) x (N - 2) x ... 1)

          =  (N + 1 - 1) x (N x (N - 1) x (N - 2) x ... 1)

          =  ((N + 1) x N x (N - 1) x (N - 2) x ... 1) 
              - (N x (N - 1) x (N - 2) x ... 1)

          =  (N + 1)! - N!

Now, it is "intuitively obvious" 1 that O((N + 1)! - N!) is the same as O((N+1)!) ... and this can be proved from first principles. 现在,“直观上显而易见” 1 O((N + 1)! - N!)O((N+1)!) ...相同,这可以从第一原理中得到证明。

Also, it is "intuitively obvious" that O(N!N) is N times as expensive as O(N!) which puts it into a different complexity class. 而且,“直观上”是O(N!N)价格是O(N!) N倍,这使O(N!N)成为不同的复杂度类别。 (Just like O(N) and O(N^2) are different complexity classes!) (就像O(N)O(N^2)是不同的复杂度类!)


But here's the thing. 但是,这就是事情。 The O(N!) complexity class is clearly problematic for practical computations as N gets large. N变大时, O(N!)复杂度类对于实际计算显然是有问题的。 It is substantially worse than simple exponential. 它远比简单指数差。

  N!   ~=  N^N for large N  // by Stirling's Approximation

  N^N   =  e^(NlogN)

  e^(NlogN) >> e^N for large N

So basically, whether you have O(N!) or O(N!N) you have a big problem ... either way. 因此,基本上,无论您是O(N!)还是O(N!N)您都会遇到一个大问题……


1 - Statements like "intuitively obvious" are not proper maths. 1-像“直觉上显而易见的”这样的陈述不是正确的数学。 Obviously. 明显。

O(n!*n) is rather high complexity. O(n!* n)的复杂度很高。 But since there is multiplication you cannot remove second n. 但是由于存在乘法,所以您不能删除第二个n。 But if there was addiction like o(n!+n) then n could be omitted since for big values of n, n is not significant compared to n! 但是,如果有喜欢Ø瘾(N!+ N)则n可能因为被省略n个大值, n相比并不显著n!

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

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