Binomial Coefficients In probability and statistics applications, you often need
ID: 3680168 • Letter: B
Question
Binomial Coefficients In probability and statistics applications, you often need to know the total possible number of certain outcome combinations. For example, you may want to know how many ways a 2-card Blackjack hand can be dealt from a 52 card deck, or you may need to know the number of possible committees of 3 people that can be formed from a 12-person department, etc. The binomial coefficient (often referred to as "n choose k") will provide the number of combinations of k things that can be formed from a set of n things. The binomial coefficient is written mathematically as: (n k) which we refer to as "n choose k". Binomial coefficients can be defined recursively: (n k) = (n-1 k-1) + (n-1 k), (n 0) = (n n) = 1 Individually, write a recursive function named choose (int n, int k) that will compute and return the value of the binomial coefficient. Then compare your function to your partner's, and together come up with a function implementation you both agree on, and write it as a C++ function on the computer. Then use your function to determine the number of 5-card poker hands that can be dealt from a 52 card deck.Explanation / Answer
Implementation of Binomial Coefficient:-
#include<bits/stdc++.h>
using namespace std;
int binomialCoeff(int n,int k)
{
//Base Case
if(k==0||k==n)
return 1;
//Recurring
return binomialCoeff(n-1,k-1)+binomialCoeff(n-1,k);
}
int main()
{
int n,k;
cout<<"Enter the value of n: ";
cin>>n;
cout<<" Enter the value of k: ";
cin>>k;
if(n>=k)
{
cout<<binomialCoeff(n,k);
}
else
{
cout<<"Put proper values for n"; //When nis less than k then nCk is not defined.
}
}
if you have any doubts please comment below....
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.