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
-1
votes
4 answers

Java: Expression including binomial coefficient calculation

Task is to calculate expression for natural numbers entered. I know I should calculate binominal coefficient here right? Also I know that (-1)^p determines whether this array is decrementing or incrementing, but don't know how to use p in my…
Temp034
  • 141
  • 11
-1
votes
1 answer

How do I implement negative numbers into this binomial coefficients method?

private long binomial(int n, int k) { if (k == 0 || k == n) { return 1; } else if (k > n) { return 0; } else if (0 < k && k < n) { return binomial(n - 1, k - 1) + binomial(n - 1, k); } return 0; } Hi,…
Andrew Coates
  • 119
  • 2
  • 12
-1
votes
1 answer

Binomial coefficient and time congestion Propabillity Python

def binomialco(p,k): Sum = 1 Pro = 1 for i in range(0,k): Sum = Sum*(p-i) for i in range(1,k+1): Pro = Pro*i return float(Sum/Pro) def P0(s,n,v,h): athroisma = 0 for i in range(0,s+1): dent= binomialco(n-1,i)*(v*h)**i …
Harr Tou
  • 41
  • 2
  • 9
-1
votes
1 answer

Binomical coefficient using the memoizazion methood

I wrote a function that recursively calculates the binomical coefficient term of n and k using the memoizazion methood, I get an OutOfBoundException when i execute, I'll be happy to hear some directions about the mistake I've done. Thank you all.…
Mic
  • 11
  • 2
-1
votes
4 answers

C++: How do I produce the 'nth' line of Pascal's Triangle?

Here is my code: #include using namespace std; int main() { int n,k,i,x; cout << "Enter a row number for Pascal's Triangle: "; cin >> n; for(i=0;i<=n;i++) { x=1; for(k=0;k<=i;k++) { …
podomunro
  • 495
  • 4
  • 16
-1
votes
3 answers

Binomial coefficient function C++ incorrect answer n>13

I'm trying to learn C++ and hence I'm trying to do a function to calculate the binomial coefficient. The code works up to a n of 12, for larger values the generated result is incorrect. I'm grateful for your input. long double binomial(int n, int…
GustafG
  • 3
  • 1
-2
votes
2 answers

Printing python variables to a txt file

Im currently trying to print the variable div to a txt file I've created called "Calculations.txt" import math n = int(input("Enter a value for n: ")) k = int(input("Enter a value for k: ")) if k == n: print(1) elif k == 1: print(n) elif k…
-2
votes
1 answer

How to fully return from recursion function which gives cumulative addition of each function result?

I have function to calculate binomial coefficient with this formula p(n, x) = n!/(n-x)!.x! As implementation is recursive, I want to stop the further function execution once resultant coefficient exceeds INT_MAX,and it should return -1. But instead…
Akash Pagar
  • 637
  • 8
  • 22
-2
votes
1 answer

How to convert this recursive function into an iterative version?

This code basically computes nCr to print a pascal's triangle. #include int nCr(int n,int r){ if (r == 0 || r == n || n == 1 || n == 0){ return 1; } else{ return nCr(n-1,r) + nCr(n-1,r-1); } } How would this…
-2
votes
2 answers

Code for finding binomial coefficient in iterative form

I've written the code for finding the binomial coefficient in recursive form: public int binom(int n, int k) { if (k==n || k==0) return 1; else return binom(n-1,k-1) + binom(n-1, k); } How can I rewrite this code in iterative form…
TheSaviour
  • 61
  • 1
  • 7
-2
votes
1 answer

C++ loop that run until i enter correct values

This is a program which calculates the binomial coefficient. No when i enter for k value that is > n the program crashеs.But I wonder how i can do so when I enter k> n the program to bring me back to enter new values that are correct(n>k). The…
Fingolfin
  • 17
  • 7
-2
votes
1 answer

coefficient in trigonometrics sums in Mathematica

I would like to compute coefficient in mathematica. for example I wrote this code to find the coefficients of cos(kx) in (a+b*cos(x))^4 where "a" and "b" are parameters. f[x_] := (a + b Cos[x])^4 f1[x_] := TrigReduce[f[x]] g[x_, k_] :=…
asd
  • 337
  • 3
  • 5
  • 13
-3
votes
2 answers

calculate ${2n \choose n} - {2n \choose n-1}$ for big numbers \PASCAL

hello I need to calculate this binomial coefficient ${2n \choose n} - {2n \choose n-1}$ for big numbers, and I don't know how can i use data type LongWord or QWord. Any idea? :)
MatFyzak
  • 11
  • 4
-3
votes
2 answers

How to find Choose(m, n) % P for large inputs?

P = (10^9 + 7) Choose(m, n) = m! / (n! * (m - n)!) I want to calculate the value of Choose(m, n) mod P for large m and n. How can I do that in C++ ?
user5003174
-3
votes
2 answers

How can I shave .1 seconds from the runtime of this program?

I'm working on a practice program at InterviewStreet and I have a solution that runs with a time of 5.15xx seconds, while the maximum time allowed for a java solution is 5 seconds. Is there anything I can do with what I've got here to get it under 5…
1 2 3
14
15