Search code examples
time-complexitybig-obinomial-coefficients

Is the growth of the binomial coefficient function factorial or polynomial


I have written an algorithm that given a list of words, must check each unique combination of four words in that list of words (regardless of order).

The number of combinations to be checked, x, can be calculated using the binomial coefficient i.e. x = n!/(r!(n-r)!) where n is the total number of words in the list and r is the number of words in each combination, which in my case is always 4, therefore the function is x = n!/(4!(n-4)!) = n!/(24(n-4)!). Therefore as the number of total words, n, increases the number of combinations to be checked, x, therefore increases factorially right?

What has thrown me is that WolframAlpha was able to rewrite this function as x = (n^4)/24 − (n^3)/4 + (11.n^2)/24 − n/4, so now it would appear to grow polynomially as n grows? So which is it?!

Here is a graph to visualise the growth of the function (the letter x is switched to an l)


Solution

  • For a fixed value of r, this function is O(n^r). In your case, r = 4, it is O(n^4). This is because most of the terms in the numerator are canceled out by the denominator:

    n!/(4!(n-4)!) 
       = n(n-1)(n-2)(n-3)(n-4)(n-5)(n-6)...(3)(2)(1) 
         -------------------------------------------
         4!(n-4)(n-5)(n-6)...(3)(2)(1)
    
       = n(n-1)(n-2)(n-3)
         ----------------
               4!
    

    This is a 4th degree polynomial in n.