对复杂性列表进行排序(Big O)
给定一个复杂的列表:
那么你如何按照他们的 Big O 顺序排序?
我想答案就在下面?
现在的问题是 log(n!)
如何变成 n log(n)
。我也不知道我是否得到了n!和 (n-1)!正确的。 c^n 有可能比 n! 更大吗?当c>1时n?
一般来说,我如何可视化这样的大O问题...我花了很长时间才做到这一点...与迄今为止的编码相比...任何资源,视频麻省理工学院开放课件资源,带有解释的东西
Given a list of complexities:
How do you order then in their Big O order?
I think the answer is below?
Question now is how does log(n!)
become n log(n)
. Also I don't know if I got the n! and (n-1)! right. Is it possible that c^n can be bigger than n!? When c > n?
In general how do I visualize such Big O problem ... it took me quite long to do this ... compared to coding so far ... Any resources, videos MIT Open Courseware resources, something with explaination
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想看看功能如何增长。这是 Wolfram Alpha 的快速绘图:
link
一般来说,
n^n
的增长速度比c^n
对于任何大于某些n_0
的n
(因为n
将超过c
在某个时刻,即使 c 非常大)。对数增长比二次或指数增长慢得多,比线性增长稍快。对于
O(log(n!)) = O(nlogn)
,我相信有一种叫做斯特林近似的东西。归结起来就是将O(n!) = O(n^n)
视为n! = n*(n-1)*(n-2)*...*2*1
,因此n^n = n*n*n*...*n
是一个上限。可以证明它也是一个下界,但你不需要它。由于
log(n^n) = nlogn
根据对数规则,O(log(n!) = O(log(n^n)) = O(nlogn)
。You might want to see how the functions grow. Here's a quick plot from Wolfram Alpha:
link
In general,
n^n
grows much faster thanc^n
for anyn
greater than somen_0
(becausen
will overtakec
at some point, even if c is extremely large). log grows much slower than quadratic or exponential, and slightly faster than linear.For
O(log(n!)) = O(nlogn)
, I believe there was something called Stirling's Approximation. It boils down to seeing thatO(n!) = O(n^n)
asn! = n*(n-1)*(n-2)*...*2*1
, son^n = n*n*n*...*n
is an upper bound. It can be proven that is it a lower bound as well, but you don't need that.Since
log(n^n) = nlogn
by log rules,O(log(n!) = O(log(n^n)) = O(nlogn)
.