In statistics, binomial coefficients are majorly used along with distributions. But, there is more to them when applied to computational algorithms. They are used extensively in the field of statistical machine learning as well as dynamic programming. The most basic idea about binomial coefficients is derived from a binomial distribution. The coefficients are used in the binomial theorem, and hence, the name.
Primarily, binomial coefficients have two definitions. They are as follows:
1. Binomial Coefficients for Finding Combinations
Binomial coefficients are used to find the number of ways to select a certain number of objects from the provided pool of objects. Statistically, a binomial coefficient can help find the number of ways y objects can be selected from a total of x objects. The number of y element subsets from x.
The formula is derived as:
For selecting the y element subsets from x objects, binomial coefficient or combinations possible are xCy = x! / y! * (x-y)!
This method could be incredibly useful while having to figure out the number of combinations possible from a big pool of objects. But where does this apply?
Imagine there is a class with 15 students. If you need to select a team of 7 students for a competition, you need to figure out the possible combinations. While using the formula of binomial coefficients, the answer could be calculated easily.
The total combinations = 15! / 7! * (15-7)! = 15! / 7! * 8!
Many other cases are far more complicated, in which binomial coefficients are used. For example, choosing a political party for elections, or, more specifically, a syndicate. Imagine there is a bill to pass, and you are the majority whip for the ruling party. You need to decide which votes are there and how many members will be required to vote for the bill. The members need to be from the ruling as well as the opposition party. The combinatorics can be applied to find the members to ask the votes from.
2. Binomial Coefficients for Distribution
This definition is more formal and statistical. It means finding the coefficients of a polynomial expansion. To put it simply, the binomial coefficient C(a, b) can be defined as the coefficient of x^b in the distributed form of (x+1)^a.
Let us understand this by an example.
For example, you want a polynomial expansion of (x+1)^2. If we compare it to our definition, we get a=2 and b=0,1,2.
By manual calculation we know that the expansion of (x+1)^2 = x^2 + 2x + 1. But, how are those coefficients calculated?
Let us apply the formula:
The coefficient of x^0 = C(2,0)
The coefficient of x^1 = C(2,1)
The coefficient of x^2 = C(2,2)
Hence, the expansion can be written as: C(2,0)x^0 + C(2,1)x^1 + C(2,2)x^2
The formula remains the same. C(a,b) = a! / b! * (a-b)!
Applying the same formula here, C(2,0) = 2! / 0! * (2-0)! = 1
C(2,1) = 2! / 1! * (2-1)! = 2
C(2,2) = 2! / 2! * (2-2)! = 1
Now, if we substitute these values in the expansion, we get x^2 + 2x + 1.
It is the exact answer that we required. As this was a smaller expansion, you may feel that the simple multiplication way is better. But, what if you need to calculate the expanded form of (x+1)^17?
There is no way you can multiply that many times, and it will be a tiresome job. But, with the concept of binomial coefficients, the job becomes simple.
Before implementing the formula for finding the binomial coefficients, it is necessary to note a few points. There are two parts required to implement the function. One is the substructure, and the second is a function to repeat the substructures.
To recursively find the value of C(a, b), we can use the following substructure:
C(a, 0) and C(a, a) = 1
C(a, b) = C(a-1, b) + C(a-1, b-1)
Using these two formulas, a recursive function could be implemented. Do note that on a higher degree of expansion, many of the substructures would be repeated. It could increase the computation time if the calculations are repeated unnecessarily. Hence, for effective implementation, it is important to maintain a dictionary with all the previous computations.
This type of implementation has a time complexity of O(a*b). The space complexity varies according to the implementation but can be restricted to O(b).
If you are using Python and do not want to implement the function yourself, you can use Python’s library SciPy. The special module in SciPy has the function binom(). Here is how it can be used:
Just type in, scipy.special.binom(a, b) and it will provide the value for the same. For example, scipy.special.binom(4,3); will give the output – 4.0
The primary usages of binomial coefficients have already been discussed above. Binomial coefficients are used for analysis as well as the base for the binomial distribution. A lesser-known usage is that binomial coefficients represent the entries in Pascal’s triangle. These types of statistical reasons make binomial coefficients necessary to understand.
Also Checkout: Binomial Distribution in Python with Real World Examples
So, this was all about binomial coefficients from a statistical and an implementation point of view. We discussed the two definitions of binomial coefficients, for combinations and for calculating expansion coefficients. The implementation strategy, as well as library implementation, was discussed.
There are many more statistical applications for binomial coefficients, especially when they are seen with the distributions. And hence, it is crucial to learn about the binomial coefficients before heading towards advanced statistics-based concepts like core machine learning and analysis algorithms.
If you’re interested to learn more about machine learning, check out IIIT-B & upGrad’s PG Diploma in Machine Learning & AI which is designed for working professionals and offers 450+ hours of rigorous training, 30+ case studies & assignments, IIIT-B Alumni status, 5+ practical hands-on capstone projects & job assistance with top firms.