Java Binomial Coefficients binomialCoeff(int n, int k)

Here you can find the source of binomialCoeff(int n, int k)

Description

Multiplicative form from Wikipedia

License

BSD License

Declaration

public static long binomialCoeff(int n, int k) 

Method Source Code

//package com.java2s;
// BSD License (http://lemurproject.org/galago-license)

public class Main {
    /** Multiplicative form from Wikipedia
      * @author irmarc/*  w  w  w.j a  va2 s.c  o  m*/
      */
    public static long binomialCoeff(int n, int k) {
        if (n <= k) {
            return 1;
        }
        int c;
        if (k > n - k) { // take advantage of symmetry
            k = n - k;
        }
        c = 1;
        for (int i = 0; i < k; i++) {
            c *= (n - i);
            c /= (i + 1);

        }
        return c;
    }
}

Related

  1. binomial(int n, double p)
  2. binomial(int n, final int k)
  3. binomial(int N, int K)
  4. binomial(int n, int k)
  5. binomialCdf(int k, int n, double p)
  6. binomialCoefficient(double n, double k)
  7. binomialCoefficient(int n, int k)
  8. binomialCoefficient(int n, int k)
  9. binomialCoefficient(int n, int k)