This function calculates the binomial coefficient

directly, using the logarithm of the Gamma function,
rather than recursively.

is the number of distinct combinations of
k objects chosen from a set
of
n distinct objects. A combination is like a set, in that order does not matter. The computed expression has
the following form:
This coefficient represents the number of distinct combinations of
k objects chosen from a set of
n distinct objects.
The advantage in using this function is that large values of
n and
k may be given, without the fear of arithmetic
overflow during the intermediate calculations. This is possible with the use of the logarithm of the Gamma function.
Example:
#include <codecogs/maths/combinatorics/arithmetic/binomial_coefficient_gamma.h>
#include <iostream>
int main()
{
for (int i = 0; i <= 6; i++)
{
std::cout << "C(6, " << i << ") = ";
std::cout << Maths::Combinatorics::Arithmetic::binomial_coefficient_gamma(6, i);
std::cout << std::endl;
}
return 0;
}Output:
C(6, 0) = 1
C(6, 1) = 6
C(6, 2) = 15
C(6, 3) = 20
C(6, 4) = 15
C(6, 5) = 6
C(6, 6) = 1
References:
SUBSET, a C++ library of combinatorial routines,
http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.htmlParameters
| n | the first combinatorial parameter |
| k | the second combinatorial parameter |
Returns
- the binomial coefficients with parameters n and k
Authors
- Lucian Bentea (August 2005)
Source Code
Source code is available when you agree to a GP Licence or buy a Commercial Licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.