The complexity of n choose 2 is in Theta (n^2)?

醉酒当歌 提交于 2019-11-29 06:14:52

问题


I'm reading Introduction to Algorithms 3rd Edition (Cormen and Rivest) and on page 69 in the "A brute-force solution" they state that n choose 2 = Theta (n^2). I would think it would be in Theta (n!) instead. Why is n choose 2 tightly bound to n squared? Thanks!


回答1:


n choose 2 is

n(n - 1) / 2

This is

n2 / 2 - n/2

We can see that n(n-1)/2 = Θ(n2) by taking the limit of their ratios as n goes to infinity:

limn → ∞ (n2 / 2 - n / 2) / n2 = 1/2

Since this comes out to a finite, nonzero quantity, we have n(n-1)/2 = Θ(n2).

More generally: n choose k for any fixed constant k is Θ(nk), because it's equal to

n! / (k!(n - k)!) = n(n-1)(n-2)...(n-k+1) / k!

Which is a kth-degree polynomial in n with a nonzero leading coefficient.

Hope this helps!



来源:https://stackoverflow.com/questions/19415988/the-complexity-of-n-choose-2-is-in-theta-n2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!