Abstract


  • The selection of items from a larger set without considering the order of selection
  • The number of combinations can be calculated using the Binomial Coefficient

Binomial Coefficient


So what is Binomial Coefficient?

  • is the number of ways, disregarding order, that objects can be chosen from among objects


  • Also known as the number of k-element Subset (or k-combinations) of a n-element Set

  • , because given a set of 2 elements for example, there are 2 subsets of 1 elements: and


  • gives the Coefficient of one of the term of the expansion Binomial
  • The term is expressed as

Binomial

  • Bi means two
  • A mathematical expression or algebraic equation that consists of two terms connected by a plus or minus sign, general form is or

Coefficient

  • Constant Factor that multiplies a variable
  • For example, is the coefficient of

Formula 1

  • Formula 1 uses Recursion

  • The idea is to fix an element x in the set. If x is included in the subset, we have to choose k − 1 elements from n − 1 elements, and if x is not included in the subset, we have to choose k elements from n − 1 elements

  • There are two independent paths here, so we perform Rule of Sum

  • Since there is recursion involved, there is base case to terminate the recursion too. The base cases are . Because there is always exactly one way to construct an empty subset and a subset that contains all the elements


  • Below is an implementation of formula 1 in Java

Exponential Time Complexity

For , formula 1 takes a few ms, while Formula 2 only takes 0ms

No Overflow Issue

As long as the given is within the range of long, we will not face any overflow issue

Formula 2

  • The divisor Divisor and avoid overcounting, includes counting that have the same set of elements but different order

  • means how many ways to choose elements from element where the order matters

  • removes the counting that has the same set of elements


  • Below is an implementation of formula 1 in Java

Linear Time Complexity

For , Formula 1 takes a few ms, while Formula 2 only takes 0ms

Overflow Issue

Try change the from to in the editor above, you should an overflow error. Because is out of the range the long can cover

We can handle this with Scientific notation - Wikipedia, but this introduces extra logic

Binomial Coefficient Properties


Symmetry Property

Proof

For :

For :

, since:

References