I know that iterating over all subsets of a set of size n is a performance nightmare and will take O(2^n) time.
How about iterating over all subsets of size k (for (
It's easy to show that for a fixed n
, (n, k)
has a maximum at k = n/2
. If I haven't misapplied Sterling's approximation, the asymptotic behavior for (n, n/2)
is exponential.
For constant k
, (n, k)
is O(n^k)
. Keep in mind that the combinatorial function is symmetric, so it's the same for (n, n-k)
. It's polynomial, so it's way smaller than O(n!)
.