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(1p)nkP(X = k) = \binom{n}{k} p^{k} (1 - p)^{\,n-k}

Cumulative Distribution Function:

P(Xk)=i=0k(ni)pi(1p)niP(X \le k) = \sum_{i=0}^{k} \binom{n}{i} p^{\,i} (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