Java Binomial Coefficients binomial(final int n, final int k)

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

Description

Compute binomial coefficient for k out of n.

License

Open Source License

Parameter

Parameter Description
n total number.
k number selected from total.

Return

the number of ways of selecting k from n.

Declaration

public static long binomial(final int n, final int k) 

Method Source Code

//package com.java2s;
/*/*from ww w.j a va 2s  .  c  o  m*/
 * Copyright (c) 2014. Real Time Genomics Limited.
 *
 * Use of this source code is bound by the Real Time Genomics Limited Software Licence Agreement
 * for Academic Non-commercial Research Purposes only.
 *
 * If you did not receive a license accompanying this file, a copy must first be obtained by email
 * from support@realtimegenomics.com.  On downloading, using and/or continuing to use this source
 * code you accept the terms of that license agreement and any amendments to those terms that may
 * be made from time to time by Real Time Genomics Limited.
 */

public class Main {
    private static final long[][] BINOMIAL = new long[65][];

    /**
     * Compute binomial coefficient for k out of n.
     * @param n total number.
     * @param k number selected from total.
     * @return the number of ways of selecting k from n.
     */
    public static long binomial(final int n, final int k) {
        if (k > n || k < 0) {
            return 0;
        }
        if (k == 0) {
            return 1;
        }
        return BINOMIAL[n][k - 1];
    }
}

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)