Java Utililty Methods Binomial Coefficients

List of utility methods to do Binomial Coefficients

Description

The list of methods to do Binomial Coefficients are organized into topic(s).

Method

longbinomial(final int n, final int k)
Compute binomial coefficient for k out of n.
if (k > n || k < 0) {
    return 0;
if (k == 0) {
    return 1;
return BINOMIAL[n][k - 1];
intbinomial(int n, double p)
binomial
assert 0.0 <= p && p <= 1.0;
int x = 0;
for (int i = 0; i < n; i++) {
    x += bernouli(p);
return x;
longbinomial(int n, final int k)
binomial
final int min = (k < n - k ? k : n - k);
long bin = 1;
for (int i = 1; i <= min; i++) {
    bin *= n;
    bin /= i;
    n--;
return bin;
...
longbinomial(int N, int K)
Compute binomial (N) (K)
assert N >= 0 : N;
assert K >= 0 : K;
long[][] binomial = new long[N + 1][K + 1];
for (int k = 1; k <= K; k++) {
    binomial[0][k] = 0;
for (int n = 0; n <= N; n++) {
    binomial[n][0] = 1;
...
intbinomial(int n, int k)
Returns binomial coefficient
if (n < 0 || k < 0 || k > n)
    return 0;
int res = 1;
for (int i = k + 1; i <= n; i++)
    res *= i;
for (int i = 2; i <= n - k; i++)
    res /= i;
return res;
...
doublebinomialCdf(int k, int n, double p)
Binomial cumulative distribution function.
double da, db, dp;
if (k < 0) {
    dp = 0.0;
} else if (k >= n) {
    dp = 1.0;
} else if (p == 0.0) {
    dp = (k < 0) ? 0.0 : 1.0;
} else if (p == 1.0) {
...
longbinomialCoeff(int n, int k)
Multiplicative form from Wikipedia
if (n <= k) {
    return 1;
int c;
if (k > n - k) { 
    k = n - k;
c = 1;
...
doublebinomialCoefficient(double n, double k)
binomial Coefficient
return factorial(n) / (factorial(k) * factorial(n - k));
doublebinomialCoefficient(int n, int k)
binomial Coefficient
double ret = 1;
for (int i = n; i > k; i--)
    ret *= i;
return ret;
longbinomialCoefficient(int n, int k)
binomial Coefficient
if (k > n)
    return 0;
long result = 1;
for (int i = 1; i <= k; i++)
    result = result * (n - k + i) / i;
return result;