Skip to content

Probability and Expected Value

Updated · Equations updated; Sections updated; Examples or practice updated; Explanations expanded What changed?
  1. — Equations updated; Sections updated; Examples or practice updated; Explanations expanded

A sample space lists the possible outcomes of a random experiment. When these outcomes are equally likely,

Pr⁡(A)=#outcomes in A#outcomes in the sample space.\Pr(A)=\frac{\#\text{outcomes in }A}{\#\text{outcomes in the sample space}}.

The equally-likely condition matters. The sums of two dice are not equally likely, but the 3636 ordered pairs of face values are.

Example. Two fair six-sided dice are rolled. Find the probability that at least one die shows a six.

Use the complement, where neither die is a six. Each die then has five allowed outcomes, so

Pr⁡(at least one six)=1−5262=1136.\Pr(\text{at least one six})=1-\frac{5^2}{6^2}=\frac{11}{36}.

Adding the two probabilities 1/6+1/61/6+1/6 without correction would count the outcome (6,6)(6,6) twice.


Conditional probability restricts attention to an event already known to have happened:

Pr⁡(A∣B)=Pr⁡(A∩B)Pr⁡(B),Pr⁡(B)>0.\Pr(A\mid B)=\frac{\Pr(A\cap B)}{\Pr(B)},\qquad\Pr(B)>0.

Events are independent if Pr⁡(A∩B)=Pr⁡(A)Pr⁡(B)\Pr(A\cap B)=\Pr(A)\Pr(B). Disjoint events cannot happen together; independent events do not change each other’s probabilities. These are different conditions.

Example. Two fair dice are rolled, and their sum is known to be even. Find the probability that both dice show odd numbers.

There are 99 odd–odd pairs and 99 even–even pairs, so the conditional sample space has 1818 equally likely outcomes. Exactly 99 satisfy the requested event. The probability is 9/18=1/29/18=1/2.

For sequential sampling without replacement, multiply conditional probabilities. For example, if a bag has three red and two blue balls, the probability of drawing two reds is (3/5)(2/4)=3/10(3/5)(2/4)=3/10, since the composition changes after the first draw.

For a partition into cases BiB_i, total probability gives Pr⁡(A)=∑iPr⁡(A∣Bi)Pr⁡(Bi)\Pr(A)=\sum_i\Pr(A\mid B_i)\Pr(B_i). Bayes’ formula reverses the conditioning:

Pr⁡(Bi∣A)=Pr⁡(A∣Bi)Pr⁡(Bi)Pr⁡(A).\Pr(B_i\mid A)=\frac{\Pr(A\mid B_i)\Pr(B_i)}{\Pr(A)}.

Use it when the outcome is known but the case that produced it is unknown.


A random variable assigns a number to each outcome. Its expected value is the probability-weighted average:

E[X]=∑xxPr⁡(X=x).\mathbb E[X]=\sum_x x\Pr(X=x).

An expectation need not be an attainable value. A fair die has expected value 7/27/2 even though no face shows 3.53.5.

For random variables with finite expectations, linearity of expectation states

E[X1+⋯+Xn]=E[X1]+⋯+E[Xn].\mathbb E[X_1+\cdots+X_n]=\mathbb E[X_1]+\cdots+\mathbb E[X_n].

No independence is required. This makes it possible to average a complicated total without finding its entire distribution.

Example. Six fair dice are rolled. Find the expected sum of their face values.

Each die has mean (1+2+3+4+5+6)/6=7/2(1+2+3+4+5+6)/6=7/2. Add the six expectations to get 6(7/2)=216(7/2)=21.


An indicator IAI_A equals one when event AA occurs and zero otherwise. Therefore E[IA]=Pr⁡(A)\mathbb E[I_A]=\Pr(A). If XX counts how many events occur, write it as a sum of indicators.

Example. A uniformly random permutation of n≥1n\ge1 distinct objects is chosen. Find the expected number of fixed points.

Let Ii=1I_i=1 if position ii contains its original object. Exactly (n−1)!(n-1)! of the n!n! permutations fix that position, so E[Ii]=1/n\mathbb E[I_i]=1/n. Thus

E[X]=∑i=1nE[Ii]=n⋅1n=1.\mathbb E[X]=\sum_{i=1}^n\mathbb E[I_i]=n\cdot\frac1n=1.

The indicators are dependent, but linearity still applies.

Example. Each of five people independently chooses one of four rooms uniformly. Find the expected number of nonempty rooms.

For a particular room, the probability everyone avoids it is (3/4)5(3/4)^5. Its nonempty indicator therefore has expectation 1−(3/4)51-(3/4)^5. Summing over rooms gives

E[X]=4(1−(34)5)=781256.\mathbb E[X]=4\left(1-\left(\frac34\right)^5\right)=\frac{781}{256}.

If independent trials each succeed with fixed probability p>0p>0, the expected waiting time for the first success is 1/p1/p. Let EE be that expected time. After one trial, success finishes the experiment, while failure returns to the starting situation:

E=1+(1−p)E⟹E=1p.E=1+(1-p)E\quad\Longrightarrow\quad E=\frac1p.

For patterns, success chances depend on recent outcomes. Define a state containing just enough history to describe the next transition.

Example. A fair coin is tossed repeatedly. Find the expected number of tosses needed to see two consecutive heads.

Let E0E_0 be the remaining expectation when there is no trailing head, and E1E_1 the expectation after one trailing head. Count the next toss in each equation:

E0=1+12E0+12E1,E_0=1+\frac12E_0+\frac12E_1, E1=1+12E0+12(0).E_1=1+\frac12E_0+\frac12(0).

The zero corresponds to another head, which completes the pattern. The first equation gives E0=2+E1E_0=2+E_1. Substituting into the second yields E0=6E_0=6. We start in state zero, so the answer is six tosses.

Choosing Between Binomial and Hypergeometric Models

Section titled “Choosing Between Binomial and Hypergeometric Models”

Repeated independent trials with the same success probability pp produce a binomial count. Exactly kk successes in nn trials have probability

(nk)pk(1−p)n−k.\binom nk p^k(1-p)^{n-k}.

Choose the success positions, then multiply the probabilities along that specified pattern. Independence and a fixed probability are both required.

Sampling without replacement from a finite population gives a different model. If KK of NN objects are marked and nn objects are chosen uniformly, exactly kk marked objects occur with probability

(Kk)(N−Kn−k)(Nn).\frac{\binom Kk\binom{N-K}{n-k}}{\binom Nn}.

This is the hypergeometric formula. The numerator chooses the marked and unmarked portions of the sample. Unlike sequential multiplication, it avoids keeping track of the changing composition after each draw.

Example. Five objects are chosen uniformly without replacement from eight red and seven blue objects. Find the probability of exactly three reds.

A sample is an unordered five-element subset, so the probability is

(83)(72)(155)=56⋅213003=56143.\frac{\binom83\binom72}{\binom{15}5} =\frac{56\cdot21}{3003} =\frac{56}{143}.

The binomial expression (53)(8/15)3(7/15)2\binom53(8/15)^3(7/15)^2 would describe replacement sampling instead and is not correct for this experiment.


When an experiment first selects a source and then produces an observation, condition on the source before calculating the observation probability. Bayes’ formula then updates the source probabilities after the observation is known.

Example. Urn A is chosen with probability one-third and contains white balls with proportion two-thirds. Urn B is chosen with probability two-thirds and has white proportion one-quarter. A ball drawn from the selected urn is white. Find the probability that A was chosen.

The two disjoint ways to observe white have probabilities

Pr⁡(A∩W)=13⋅23=29,Pr⁡(B∩W)=23⋅14=16.\Pr(A\cap W)=\frac13\cdot\frac23=\frac29,\qquad \Pr(B\cap W)=\frac23\cdot\frac14=\frac16.

Thus Pr⁡(W)=7/18\Pr(W)=7/18, and

Pr⁡(A∣W)=2/97/18=47.\Pr(A\mid W)=\frac{2/9}{7/18}=\frac47.

The posterior is greater than one-third because a white ball is more likely under A. This directional check helps catch an inverted conditional probability.

The observation mechanism matters. If a host or observer chooses what to reveal, their rule can change the conditional sample space. State the rule before assigning probabilities; “one possibility was removed” does not automatically make the remaining possibilities equally likely.


Indicators are useful even when the total is not visibly a count of separate objects. A count of pairs suggests one indicator per pair; a count of adjacency events suggests one per edge or neighboring position.

Example. A uniformly random permutation of 1,…,n1,\ldots,n is chosen. Find the expected number of inversions, pairs i<ji<j whose values occur in reverse order.

For each pair of distinct values a<ba<b, let its indicator be one when bb appears before aa. The two relative orders are equally likely, so each indicator has expectation one-half. There are (n2)\binom n2 pairs, giving

E[X]=12(n2)=n(n−1)4.\mathbb E[X]=\frac12\binom n2=\frac{n(n-1)}4.

Dependence among the pair indicators does not matter for this expectation.

Example. In a random permutation of 1,…,n1,\ldots,n with n≥2n\ge2, find the expected number of pairs of consecutive values that occupy adjacent positions.

For a specified pair {k,k+1}\{k,k+1\}, treat the values as a block. There are 2(n−1)!2(n-1)! permutations placing them together, so the probability is 2/n2/n. Summing the indicators for the n−1n-1 consecutive-value pairs gives

E[X]=(n−1)2n=2−2n.\mathbb E[X]=(n-1)\frac2n=2-\frac2n.

A run containing three consecutive values may contribute two indicators, which is appropriate because the requested quantity counts pairs, not runs.

This last distinction is important. If the problem asks for maximal runs, an indicator for every adjacent match counts the wrong object. Define the random variable before choosing its decomposition.


For a nonnegative integer-valued random variable,

E[X]=∑k≥1Pr⁡(X≥k)\mathbb E[X]=\sum_{k\ge1}\Pr(X\ge k)

whenever the expectation is finite, with the same identity allowing infinity. An outcome with value mm contributes one to exactly the first mm tail indicators. This representation is useful when the probability of exceeding a threshold is easier than the probability of one exact value.

Another useful decomposition splits a waiting process into stages. Collecting a new type after several types are already known is a geometric wait with a changing success probability.

Example. A fair six-sided die is rolled until every face has appeared. Find the expected number of rolls.

After kk distinct faces have appeared, the next roll introduces a new face with probability (6−k)/6(6-k)/6. The expected wait for that next new face is 6/(6−k)6/(6-k). Add the six stage expectations:

E[T]=6(1+12+13+14+15+16)=14710.\mathbb E[T]=6\left(1+\frac12+\frac13+\frac14+\frac15+\frac16\right) =\frac{147}{10}.

The stage waiting times need not be proved independent to add their expectations. What matters is that they sum to the total collection time and each stage has the stated geometric distribution.

For nn equally likely types, the same argument gives nHnnH_n, where Hn=1+1/2+⋯+1/nH_n=1+1/2+\cdots+1/n. If the types have different probabilities, the success chance depends on which types are missing, not just how many. A single count state no longer determines the process.


Hitting Probabilities and Expected Duration

Section titled “Hitting Probabilities and Expected Duration”

State recurrences can calculate either a probability or an expectation, but the equations differ. A hitting probability averages the next-state probabilities. An expected remaining duration adds one for the next move before averaging.

Consider a fair random walk on integers 0,1,…,N0,1,\ldots,N, stopping at either endpoint. Let pip_i be the probability of reaching NN first from state ii. Then

p0=0,pN=1,pi=12pi−1+12pi+1.p_0=0,\quad p_N=1,\quad p_i=\frac12p_{i-1}+\frac12p_{i+1}.

The interior equation says consecutive differences are equal, so pi=i/Np_i=i/N.

For expected duration EiE_i, the equations are

E0=EN=0,Ei=1+12Ei−1+12Ei+1.E_0=E_N=0,\qquad E_i=1+\frac12E_{i-1}+\frac12E_{i+1}.

A quadratic trial gives Ei=i(N−i)E_i=i(N-i). It satisfies both boundary values and the recurrence. The finite absorbing system has a unique solution; absorption has finite expectation because every block of sufficiently many moves has a fixed positive chance of reaching a boundary.

Example. A player starts with three dollars and repeatedly wins or loses one dollar with equal probability, stopping at zero or ten dollars. Find the probability of reaching ten and the expected number of games.

Take N=10,i=3N=10,i=3. The hitting probability is 3/103/10, while the expected number of games is 3(10−3)=213(10-3)=21. These are different random quantities and come from different state equations.


Expectation describes the average, while variance measures spread:

Var⁡(X)=E[(X−E[X])2]=E[X2]−E[X]2.\operatorname{Var}(X)=\mathbb E[(X-\mathbb E[X])^2] =\mathbb E[X^2]-\mathbb E[X]^2.

For a Bernoulli indicator with success probability pp, the variance is p(1−p)p(1-p) because I2=II^2=I. For independent random variables, variances add. Without independence, covariance terms appear:

Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)+2(E[XY]−E[X]E[Y]).\operatorname{Var}(X+Y)=\operatorname{Var}(X)+\operatorname{Var}(Y) +2\bigl(\mathbb E[XY]-\mathbb E[X]\mathbb E[Y]\bigr).

This is why linearity of expectation cannot be copied blindly into a variance calculation. For example, if Y=XY=X, then Var⁡(X+Y)=4Var⁡(X)\operatorname{Var}(X+Y)=4\operatorname{Var}(X), not twice the variance. A contest problem asking for a second moment usually requires analyzing pairs of indicators and the probability that both events occur.


Second moments show precisely where dependence enters an indicator calculation. For a random permutation of n≥2n\ge2 objects, let XX count fixed points and write X=∑iIiX=\sum_iI_i.

Since Ii2=IiI_i^2=I_i,

X2=∑iIi+2∑i<jIiIj.X^2=\sum_iI_i+2\sum_{i<j}I_iI_j.

A specified pair of positions is fixed in (n−2)!(n-2)! of the n!n! permutations, so its joint probability is 1/[n(n−1)]1/[n(n-1)]. Therefore

E[X2]=1+2(n2)1n(n−1)=2.\mathbb E[X^2]=1+2\binom n2\frac1{n(n-1)}=2.

The mean is one, hence Var⁡(X)=2−1=1\operatorname{Var}(X)=2-1=1.

This result does not follow by adding the individual indicator variances, because those indicators are not independent. The pair terms supplied the missing information. At n=1n=1 the fixed-point count is constantly one and has variance zero, so that boundary case must be excluded from the formula.

The same expansion works for counts of collisions, adjacent matches, or intersecting pairs. Separate pairs of indicators by whether their underlying objects overlap, calculate each joint probability, and combine the categories.


A uniform permutation of nn objects can be built from a uniform permutation of n−1n-1 objects in cycle notation. Insert the new object after any one of the existing n−1n-1 objects, or let it form its own cycle. These are nn equally weighted choices, and deleting the new object reverses the construction uniquely.

Only the singleton choice increases the cycle count. Therefore

E[Cn]=E[Cn−1]+1n,\mathbb E[C_n]=\mathbb E[C_{n-1}]+\frac1n,

and the initial value one gives E[Cn]=Hn\mathbb E[C_n]=H_n.

The expected count grows slowly even though a permutation can have anywhere from one to nn cycles. This is another example where a recursive construction makes the expectation easier than the entire distribution.

Uniformity is the key justification: selecting an insertion position with arbitrary unequal probabilities would not generate a uniform permutation and would change the calculation.