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!
The function itself grows quadratically. Computing it actually only takes one multiplication operation, one subtraction, and one division by 2, so computing f(n) can be done in O(1) (assuming constant-time arithmetic operations).
Since n2 = O(n3), then any f(n) = O(n2) is also O(n3). Definition 9.2 (Big-Omega: Lower Bound) f(n) = Ω(g(n)) means there exists some constant c such that f(n) ≥ c · g(n), for large enough n (that is, as n → ∞).
Thus, the complexity is O(n choose k) .
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With