---
id: 607
lang: en
translation_of: index.md
source_sha256: bf0e0870f7c1e5df03b665c01f1fa24e3be0b2f63fc04736452bb8ed5b0a46bb
title: "Probability & Mathematical Expectation"
description: "An introduction to probability for OI: sample spaces, events, the axioms, conditional probability, the law of total probability and Bayes' formula."
tags: ["OI","Math","Expected Value","Expected Value","Probability"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "The Chinese edition's title 《概率论基础教程》 was kept as written next to the English title, as in the original."
  - "我们就乘事件发生了 (sic) read as 称, “we say the event occurred”."
  - "The definition of mutually exclusive events omits “= ∅” after E_1 ∩ E_2 in the original; translated as written."
  - "占总结过的比例 (sic) read as 总结果, “the proportion of all outcomes”."
  - "放在有口袋 (sic) read as 右口袋, “the right pocket”."
  - "定义R,L为把钥匙放在左、右口袋 pairs R with left and L with right in the original's word order; kept as written."
  - "The garbled gloss on P(AB) = P(B|A)P(A) (在A发生的情况下B发生的概率在A发生的情况下的概率) was translated as literally as possible."
  - "Tags 数学期望 and 期望 both map to Expected Value in tags.yaml, so the English tag list repeats it."
---

## Contents

- Overview
- Probability
  - Concepts Related to Probability
  - The Meaning of Probability
  - Probability of Simultaneous Occurrence
  - Axioms & Propositions of Probability
  - Conditional Probability
    - Concept
    - Law of Total Probability
    - Bayes' Formula
    - Examples
  - Random Variables
  - Applications of Probability in OI
- Mathematical Expectation
  - The Concept of Mathematical Expectation
  - Linearity of Expectation & Recurrences
  - Applications of Mathematical Expectation in OI

<!--more-->

## Overview

Math takes up a large share of OI, mainly number theory, combinatorics, and probability and expectation. I recommend that readers learn permutations and combinations first before reading this article. In this article, I'm going to properly explain what probability and expectation are all about. I will explain it through mathematical concepts and OI problems. The concepts I learned all come from 《概率论基础教程》 — “A First Course in Probability”; readers interested in learning more can go take a look.

## Probability

### Concepts Related to Probability

**Sample space**: the set of all possible outcomes of an experiment is called the sample space of that experiment, usually written as $S$.\
**Event**: a subset of the sample space is called an event; if the outcome of a trial is contained in the event, we say the event occurred. It is usually written as $E$ and can be understood as a set; for example, the event that at least one of two coins lands up can be written as $E=\{ (Up,Down),(Up,Up),(Down,Up) \}$.\
**Mutually exclusive events**: if there are two events $E_1,E_2$ and $E_1 \cap E_2$, then events $E_1,E_2$ are called mutually exclusive.\
**Complement transformation**: within a set, if the answer set $S_{ans}$ is hard to count, we can count its complement and use inclusion–exclusion to do a complement transformation: having found its complement $S_{rev}$, the answer set is $S_{ans}=S-S_{rev}$.\
**Probability**: can be approximated as the proportion of all outcomes that a given event takes up in an experiment. So,
$$
P(E)=\lim_{n \to \infty} \frac{n(E)}{n}
$$
where $n(E)$ is the number of times it occurs in $n$ events. But theory and experiment always deviate somewhat, so to keep the math rigorous, probability is simply defined as this.

### The Meaning of Probability

Probability is a very <span class="slang" data-zh="玄学" data-gloss="xuánxué, “metaphysics”. Something that seems to run on luck or mysterious rules rather than logic.">black magic</span> sort of thing, so let's explain the formula above:
$$
P(E)=\lim_{n \to \infty} \frac{n(E)}{n}
$$

In the formula above, $P$ stands for some experiment, and $P(E)$ stands for the probability of event $E$ in the experiment, that is, the number of times event $E$ occurs within a certain number of trials, divided by that number of trials. As the number of trials $n$ tends to infinity, the probability becomes more and more accurate.

### Probability of Simultaneous Occurrence

Now we have two events $E,F$, and we write the probability that these two events occur at the same time as $P(E \cap F)$, also written $P(EF)$. Here, $EF$ is defined as $E \cap F$, i.e. the intersection of the two events.

### Axioms & Propositions of Probability

**Axiom 1**
$$
0 \leq P(E) \leq 1
$$
**Axiom 2**\
For an experiment $P$, the probability of its sample space is:
$$
P(S)=1
$$
**Axiom 3**\
For a sequence of **mutually exclusive events** $E_1,E_2,\dots$, that is, $\forall i,j,E_i \cap E_j = \emptyset$, we have

$$
P(E_1 \cup E_2 \cup E_3 \cup \dots) = \sum_{i=1}^{\infty}P(E_i)
$$

Here, a probability only counts as a probability if it satisfies the three axioms above.

**Proposition 1**\
For $P(E \cup F)$, we have the formula:
$$
P(E \cup F) = P(E) + P(F) - P(EF)
$$
It can be proved with a Venn diagram.

### Conditional Probability

#### Concept

As the name suggests, the concept of conditional probability is about the probability of an event occurring when a condition occurs. We write the probability of event $E$ occurring given that event $F$ occurs as $P(E|F)$. Here, we have the formula

$$
P(E|F) = \frac {P(EF)}{P(F)}
$$

My personal understanding: for event $E$, given that event $F$ occurs, the sample size shrinks from $1$ to $P(F)$, and the probability of both occurring at once is $P(EF)$; naturally, under the condition (that $F$ occurred), the probability becomes the ratio of the probability of occurring to the sample size.

##### Example 2a (Page 49 of the original book)

> Joey is 80% certain that he put his missing key in one of the two pockets of his jacket. He is 40% sure he put it in the left pocket, and 40% sure he put it in the right pocket. If he checks the left pocket and does not find the key, what is the probability that the key is in the right pocket?

This is a classic conditional probability problem. Define $R,L$ as the two events of putting the key in the left and right pockets; we can first write down the expression:

$$
P(R|L^c) = \frac{P(RL^c)}{P(L^c)}
$$

Here the intersection of events $RL^c$ evaluates to $R$, which simplifies to:

$$
=\frac{P(R)}{1-P(L)}
$$

The result is then obvious.

#### Law of Total Probability

Consider a partition of the sample space:
$$
E_1, E_2, \dots, E_n, \forall E_i \cap E_j = \emptyset, \bigcup_i E_i = U
$$

We can ~~<span class="slang" data-zh="感性的" data-gloss="gǎnxìng de, “perceptually”. OI slang for arguing by hand-wavy intuition instead of a rigorous proof.">hand-wavily</span>~~ derive a formula:

$$
P(E) = \sum_i P(E|E_i)*P(E_i)
$$

This is the famous law of total probability. We can understand the formula from this angle: the probability of an event occurring is actually equivalent to the probability of it occurring under any circumstances, which equals the union of it occurring under each circumstance; very easy to understand. Sometimes you can go at problems this way.

#### Bayes' Formula

Bayes' formula looks like this:

$$
P(A|B) = \frac{P(AB)}{P(B)} = \frac{P(B|A)P(A)}{P(B)}
$$

This actually only takes a little shifting around of conditional probability to prove. $P(AB) = P(B|A)P(A)$ can be understood as, given that $A$ occurs, the probability of $B$ occurring, in the probability of $A$ occurring. The two are equivalent.
