Questions tagged [binomial-coefficients]

It is the coefficient of the `x^k` term in the polynomial expansion of the binomial power `(1 + x)^n` which is `(n!)/((n-k)!*k!)`.

It is the coefficient of the x^k term in the polynomial expansion of the binomial power (1 + x)^n which is (n!)/((n-k)!*k!).

This family of numbers also arises in many areas of mathematics other than algebra, notably in combinatorics. For any set containing n elements, the number of distinct k-element subsets of it that can be formed (the k-combinations of its elements) is given by the binomial coefficient C(n, k). Therefore C(n, k) is often read as "n choose k".

213 questions
5
votes
2 answers

Calculate binomial coffeficient very reliably

What is the best method to calculate a binomial coefficient in C++? I've seen some code fragments but it seemed to me that it is always only doable in some specific region. I need a very, very, very reliable calculation. I tried it with a gamma…
Ben
  • 1,432
  • 4
  • 20
  • 43
5
votes
2 answers

Binomial Coefficient using Tail Recursion in LISP

I want to program a function to find C(n,k) using tail recursion, and I would greatly appreciate your help. I have reached this: (defun tail-recursive-binomial (n k) (cond ((or (< n k) (< k 0)) NIL) ((or (= k 0) (= n k)) 1) (T (*…
Jk041
  • 934
  • 1
  • 15
  • 33
5
votes
2 answers

glm switches coefficient names for interactions

I use the R code: dat<-data.frame(p1=c(0,1,1,0,0), GAMMA.1=c(1,2,3,4,3), VAR1=c(2,2,1,3,4), GAMMA.2=c(1,1,3,4,1)) form <- p1 ~ GAMMA.1:VAR1 + GAMMA.2:VAR1 mod <- glm(formula=form, data=dat, family=binomial) (coef <- coefficients(mod)) # (Intercept)…
Giuseppe
  • 786
  • 1
  • 7
  • 18
5
votes
2 answers

finding binomial co-effecient modulo prime number,Interview street challenge

I have done a lot of work on this but couldnt find the answer for larger test cases Problem statement In mathematics, binomial coefficients are a family of positive integers that occur as coefficients in the binomial theorem. C(n,k) denotes the…
4
votes
4 answers

How to calculate binomial coefficents for large numbers

I need to calculate n!/(n-r)!r! in C#. It's easy to calculate using the factorial function for small numbers but when the number gets bigger like 100, it doesn't work. Is there any other way with which we can calculate combinations for larger…
Jay
  • 373
  • 8
  • 22
4
votes
1 answer

GCD of two binomial coefficients modulo 10^9 + 7

There are given 0 ≤ k ≤ n ≤ 500000, 0 ≤ l ≤ m ≤ 500000. I need co calculate GCD(C(n, k), C(m, l)) modulo 10^9 + 7. My attempt: I thought about tricks with fourmula: C(n, k) = n*(n-1)*...*(n-k+1) / k! For example, suppose l >= k: GCD( C(n, k), C(m,…
4
votes
5 answers

Binomial coefficient

'Simple' question, what is the fastest way to calculate the binomial coefficient? - Some threaded algorithm? I'm looking for hints :) - not implementations :)
4
votes
3 answers

Remove intercept from GLM with multiple factor predictors

I am running a binomial logistic regression with a logit link function in R. My response is factorial [0/1] and I have two multilevel factorial predictors - let's call them a and b where a has 4 factor levels (a1,a2,a3,a4) and b has 9 factor…
MiMi
  • 548
  • 1
  • 5
  • 8
4
votes
1 answer

Binomial Coefficient in C program explanation

So I have to write a program that prints out the eleven 10th order binomial coefficients. I came across this code that does what I needed, but I'm trying to understand why it works. #include int binomialCoeff(int n, int k) { if(k…
Rick
  • 79
  • 1
  • 8
4
votes
2 answers

Algorithm to find Sum of the first r binomial coefficients for fixed n modulo m

I am trying to find the sum of the first r binomial coefficients for a fixed n. (nC1 + nC2 + nC3 + ... + nCr) % M where r < = n. Is there an efficient algorithm to solve this problem ?
Rohit Sharma
  • 73
  • 1
  • 7
4
votes
3 answers

Tail recursive binomial coefficient function in Haskell

I have a function that calculates the binomial coefficient in Haskell, it looks like this: binom :: Int -> Int -> Int binom n 0 = 1 binom 0 k = 0 binom n k = binom (n-1) (k-1) * n `div` k Is it possible to modify it and make it tail recursive?
4
votes
2 answers

Get coefficients of symbolic polynomial in Matlab

I have a Matlab function that returns a polynomial of the form: poly = ax^2 + bx*y + cy^2 where a, b, and c are constants, and x and y are symbolic (class sym). I want to get the coefficients of the polynomial in the form [a b c], but I'm running…
4
votes
3 answers

Get binomial coefficients

In an attempt to vectorize a particular piece of Matlab code, I could not find a straightforward function to generate a list of the binomial coefficients. The best I could find was nchoosek, but for some inexplicable reason this function only…
nispio
  • 1,743
  • 11
  • 22
4
votes
0 answers

Warnings while fitting negative binomial distribution in R

I am trying to fit the negative binomial ditribution in R using the following code: negfit <- fitdistr(Probhist$DemandQuantity,"negative binomial") coef(negfit) Data looks as below: Probhist <- data.frame( DemandQuantity=rep( c(0, 1, 2, 3, 4,…
4
votes
3 answers

Calculate Nth multiset combination (with repetition) based only on index

How can i calculate the Nth combo based only on it's index. There should be (n+k-1)!/(k!(n-1)!) combinations with repetitions. with n=2, k=5 you get: 0|{0,0,0,0,0} 1|{0,0,0,0,1} 2|{0,0,0,1,1} 3|{0,0,1,1,1} 4|{0,1,1,1,1} 5|{1,1,1,1,1} So…
1
2
3
14 15