KatInterview

Binomial Process Modeling and Moment Computation

Arrays & HashingAuto-graded · 23 test cases
EasyAuto-gradedArrays & Hashingbinomialprobabilitystatistics

Last 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:
    1. "There is a fixed number n of trials."
    2. "Each trial has two possible outcomes: success or failure."
    3. "The trials are independent."
    4. "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 expectation E[X] = n * p (as a number).
  • "variance": The calculated variance Var[X] = n * p * (1 - p) (as a number).

Constraints

  • n is an integer such that n >= 1.
  • p is a float such that 0.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.