Binomial Process Modeling and Moment Computation
Arrays & HashingAuto-graded · 23 test casesLast updated
Return theoretical properties and compute the expected value and variance for a Binomial random variable given sample size n and success probability p.
Given a number of independent Bernouli trials n and a constant success probability p, construct a detailed summary dictionary of the underlying random variable's probability model.
The summary dictionary must contain the exact key-value pairs specified below:
"distribution":"Binomial(n, p)""assumptions": A list of four structural assumptions in this exact order:"There is a fixed number n of trials.""Each trial has two possible outcomes: success or failure.""The trials are independent.""The probability of success p is constant for every trial."
"pmf":"P(X = k) = C(n, k) * p^k * (1 - p)^(n - k), for k = 0, 1, ..., n""expected_value_formula":"E[X] = n * p""variance_formula":"Var[X] = n * p * (1 - p)""expected_value": The calculated expectationE[X] = n * p(as a number)."variance": The calculated varianceVar[X] = n * p * (1 - p)(as a number).
Constraints
nis an integer such thatn >= 1.pis a float such that0.0 <= p <= 1.0.
Examples
Example 1
Input: identify_binomial_model(10, 0.2)
Output: {'distribution': 'Binomial(n, p)', 'assumptions': ['There is a fixed number n of trials.', 'Each trial has two possible outcomes: success or failure.', 'The trials are independent.', 'The probability of success p is constant for every trial.'], 'pmf': 'P(X = k) = C(n, k) * p^k * (1 - p)^(n - k), for k = 0, 1, ..., n', 'expected_value_formula': 'E[X] = n * p', 'variance_formula': 'Var[X] = n * p * (1 - p)', 'expected_value': 2, 'variance': 1.6}
Example 2
Input: identify_binomial_model(3, 0.5)
Output: {'distribution': 'Binomial(n, p)', 'assumptions': ['There is a fixed number n of trials.', 'Each trial has two possible outcomes: success or failure.', 'The trials are independent.', 'The probability of success p is constant for every trial.'], 'pmf': 'P(X = k) = C(n, k) * p^k * (1 - p)^(n - k), for k = 0, 1, ..., n', 'expected_value_formula': 'E[X] = n * p', 'variance_formula': 'Var[X] = n * p * (1 - p)', 'expected_value': 1.5, 'variance': 0.75}
Example 3
Input: identify_binomial_model(1, 0.75)
Output: {'distribution': 'Binomial(n, p)', 'assumptions': ['There is a fixed number n of trials.', 'Each trial has two possible outcomes: success or failure.', 'The trials are independent.', 'The probability of success p is constant for every trial.'], 'pmf': 'P(X = k) = C(n, k) * p^k * (1 - p)^(n - k), for k = 0, 1, ..., n', 'expected_value_formula': 'E[X] = n * p', 'variance_formula': 'Var[X] = n * p * (1 - p)', 'expected_value': 0.75, 'variance': 0.1875}
Hints
Hint 1
Recall that the mean of a Binomial distribution is n * p and the variance is n * p * (1 - p).
Hint 2
Ensure all keys match the specified string literal names exactly.
Hint 3
Check that the list of assumptions follows the required order verbatim.
Worked solution
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Approach
The problem asks for a metadata description of the Binomial distribution $\text{Binomial}(n, p)$ alongside its calculated numerical parameters.
- Model Identification: A sequence of $n$ independent trials with identical probability of success $p$ forms a standard Binomial process $X \sim \text{Binomial}(n, p)$.
- Key Formulas:
- Probability Mass Function (PMF): $P(X = k) = \binom{n}{k} p^k (1-p)^{n-k}$
- Mean / Expected Value: $E[X] = n \cdot p$
- Variance: $\text{Var}[X] = n \cdot p \cdot (1-p)$
- Assumptions:
- Fixed count of trials $n$.
- Binary outcomes (success/failure).
- Independent events across all trials.
- Stationary success probability $p$.
We assemble these mathematical definitions into the designated standard output template.
Complexity
- Time Complexity: $\mathcal{O}(1)$, since only basic arithmetic operations and fixed dictionary initialization occur.
- Space Complexity: $\mathcal{O}(1)$, as the returned output object is of fixed size.
Python Reference Solution
def identify_binomial_model(n: int, p: float) -> dict:
return {
"distribution": "Binomial(n, p)",
"assumptions": [
"There is a fixed number n of trials.",
"Each trial has two possible outcomes: success or failure.",
"The trials are independent.",
"The probability of success p is constant for every trial."
],
"pmf": "P(X = k) = C(n, k) * p^k * (1 - p)^(n - k), for k = 0, 1, ..., n",
"expected_value_formula": "E[X] = n * p",
"variance_formula": "Var[X] = n * p * (1 - p)",
"expected_value": n * p,
"variance": n * p * (1 - p)
}