问题
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