TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
Problems
Loading...
1 / 1

Binomial Probability Mass Function

Probability and Statistics
Easy

Implement the Binomial distribution Probability Mass Function (PMF) and Cumulative Distribution Function (CDF). The Binomial distribution counts the number of successes in n independent Bernoulli trials with probability p.

Binomial Distribution:

Probability Mass Function:

P(X=k)=(nk)pk(1−p) n−kP(X = k) = \binom{n}{k} p^{k} (1 - p)^{\,n-k} P(X=k)=(kn​)pk(1−p)n−k

Cumulative Distribution Function:

P(X≤k)=∑i=0k(ni)p i(1−p) n−iP(X \le k) = \sum_{i=0}^{k} \binom{n}{i} p^{\,i} (1 - p)^{\,n-i} P(X≤k)=i=0∑k​(in​)pi(1−p)n−i

Function Arguments

  • n: int - Number of trials
  • p: float - Success probability (0 ≤ p ≤ 1)
  • k: int - Number of successes (0 ≤ k ≤ n)
Loading visualization...

Examples

Input: n=5, p=0.5, k=2

Output: pmf=0.3125, cdf=0.5

Input: n=10, p=0.3, k=0

Output: pmf=0.0282, cdf=0.0282

Input: n=8, p=0.7, k=8

Output: pmf=0.0576, cdf=1.0

Hint 1

Use scipy.special.comb() for stable binomial coefficients instead of factorial.

Hint 2

For CDF, sum PMF values from i=0 to k using a loop.

Hint 3

Convert results to float: float(pmf), float(cdf).

Requirements

  • Return tuple: (pmf, cdf)
  • Both pmf and cdf: scalar floats
  • Use stable computation (no factorial loops)
  • Handle edge cases: k=0, k=n, p=0, p=1

Constraints

  • 0 ≤ k ≤ n ≤ 100
  • 0 ≤ p ≤ 1
  • NumPy + SciPy allowed; time limit: 300ms
Try Similar Problems
Bernoulli PmfPoisson Pmf CdfGeometric Pmf MeanExpected Value DiscreteSample Var Std

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: number

Accepts: number

Accepts: number

You must run your code first.
PrevNext

Binomial Probability Mass Function

Probability and Statistics
Easy

Implement the Binomial distribution Probability Mass Function (PMF) and Cumulative Distribution Function (CDF). The Binomial distribution counts the number of successes in n independent Bernoulli trials with probability p.

Binomial Distribution:

Probability Mass Function:

P(X=k)=(nk)pk(1−p) n−kP(X = k) = \binom{n}{k} p^{k} (1 - p)^{\,n-k} P(X=k)=(kn​)pk(1−p)n−k

Cumulative Distribution Function:

P(X≤k)=∑i=0k(ni)p i(1−p) n−iP(X \le k) = \sum_{i=0}^{k} \binom{n}{i} p^{\,i} (1 - p)^{\,n-i} P(X≤k)=i=0∑k​(in​)pi(1−p)n−i

Function Arguments

  • n: int - Number of trials
  • p: float - Success probability (0 ≤ p ≤ 1)
  • k: int - Number of successes (0 ≤ k ≤ n)
Loading visualization...

Examples

Input: n=5, p=0.5, k=2

Output: pmf=0.3125, cdf=0.5

Input: n=10, p=0.3, k=0

Output: pmf=0.0282, cdf=0.0282

Input: n=8, p=0.7, k=8

Output: pmf=0.0576, cdf=1.0

Hint 1

Use scipy.special.comb() for stable binomial coefficients instead of factorial.

Hint 2

For CDF, sum PMF values from i=0 to k using a loop.

Hint 3

Convert results to float: float(pmf), float(cdf).

Requirements

  • Return tuple: (pmf, cdf)
  • Both pmf and cdf: scalar floats
  • Use stable computation (no factorial loops)
  • Handle edge cases: k=0, k=n, p=0, p=1

Constraints

  • 0 ≤ k ≤ n ≤ 100
  • 0 ≤ p ≤ 1
  • NumPy + SciPy allowed; time limit: 300ms
Try Similar Problems
Bernoulli PmfPoisson Pmf CdfGeometric Pmf MeanExpected Value DiscreteSample Var Std

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: number

Accepts: number

Accepts: number

You must run your code first.