algorithm - Complexity when generating all combinations -
interview questions start "this might solved generating possible combinations array elements" meant let me find better.
anyway add "i prefer solution since o(x)".. question is: o(x) complexity of generating combinations given set?
i know there n! / (n-k)!k! combinations (binomial coefficients), how big-o notation that?
first, there nothing wrong using o(n! / (n-k)!k!)
- or other function f(n)
o(f(n))
, believe looking simpler solution still holds same set.
if willing @ size of subset k
constant,
for k<=n-k:
n! / ((n-k)!k!) = ((n-k+1) (n-k+2) (n-k+3) ... n ) / k!
but above (n^k + o(n^(k-1))) / k!
, in o(n^k)
similarly, if n-k<k
, o(n^(n-k))
which gives o(n^min{k,n-k})
Comments
Post a Comment