Skip to content

Bernoulli Distribution

Formula

\[ P(X=1)=p,\quad P(X=0)=1-p \]
\[ \mathbb{E}[X]=p,\quad \operatorname{Var}(X)=p(1-p) \]

Plot

type: bars
xs: 0 | 1
ys: 0.7 | 0.3
xmin: -0.5
xmax: 1.5
ymin: 0
ymax: 1.0
height: 280
title: Bernoulli PMF example (p=0.3)

Parameters

  • \(X\): binary random variable
  • \(p\): success probability

What it means

Models a single binary outcome.

What it's used for

  • Modeling success/failure events.
  • Building block of the binomial distribution.

Key properties

  • Support \(\{0,1\}\).
  • Mean and variance depend only on \(p\).

Common gotchas

  • Coding as \(\{-1,1\}\) changes mean and variance.
  • For repeated trials, use the binomial distribution.

Example

If \(p=0.3\), then \(P(X=1)=0.3\), \(P(X=0)=0.7\).

How to Compute (Pseudocode)

Input: distribution parameters and query values (for PMF/PDF/CDF or moments)
Output: distribution quantities

validate parameters
for each query value x (or count k):
  evaluate the PMF/PDF/CDF formula from the card
optionally compute moments/statistics from known closed forms or by summation/integration
return the requested values

Complexity

  • Time: Typically \(O(q)\) for \(q\) query values once parameters are known (assuming constant-time formula evaluation per query)
  • Space: \(O(q)\) for output values (or \(O(1)\) for a single query)
  • Assumptions: Parameter estimation/fitting cost is excluded; numerical special-function evaluation can affect constants for some families