---
id: 134
lang: en
translation_of: index.md
source_sha256: d21b0a255a2bbc30f90a3a4fdf38d5add5347d0dd19b0671a4768619e82771d4
title: "Mathematical Expectation and Its Linearity"
description: "An introduction to mathematical expectation and its linearity, with an example problem whose expectation is found by recurrence."
tags: ["OI","Math","Expected Value","Expected Value","Recurrence"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "The author wrote $数学期望$ (the term itself typeset as math); TeX is kept identical, so the Chinese characters remain inside that math span in the English."
  - "数学期望 and 期望 both map to “Expected Value” in tags.yaml, so the English tag list repeats that tag."
  - "The author's loose definition (一个有限的事件的结果乘上一个事件的概率) is translated literally, not corrected."
  - "华南师范大学附属中学 rendered with its official English name, The Affiliated High School of South China Normal University."
  - "NOIp kept as the author wrote it; 初赛 rendered as “preliminary round”."
---

## Background

Ever since the NOIp 2018 preliminary round, when I first learned that there was such a thing as mathematical expectation, I've always found it hard to understand. I never took the time to study mathematical expectation carefully, but today I took part in a contest and was forced to learn it, so now I'm writing a few things down to record this concept.

## Introducing the Concept

$数学期望$ is a concept related to probability. Its definition is:

Mathematical expectation is the outcome of a **finite** event multiplied by the probability of an event.

We can explain this concept with an example. Say we pick a random number (between 1 and 10); then the mathematical expectation of picking 5 is $\frac {1} {2}$. Usually, we use $\mathbb{E}$ to denote this value.

## Introducing the Property

In this article, I'll introduce only one property. If I learn something new about mathematical expectation in the future, I'll write it into this article.

The property of mathematical expectation that matters most in OI is its **linearity**. Simply put, if two events have mathematical expectations $\mathbb{E}(a)$ and $\mathbb{E}(b)$, then putting the two events together gives $\mathbb{E}(a) + \mathbb{E}(b) = \mathbb{E}(a+b)$. This property is fairly important in OI; some problems use it to make solvers work out the answer by recurrence. Next, let's look at a problem:

## Example Problem

Link: [T2062: Random Number Generator](https://www.luogu.org/problemnew/show/T2062)

I came across this problem in a contest held by The Affiliated High School of South China Normal University. Although I didn't get AC on this one, that doesn't stop us from explaining some properties of mathematical expectation and the method of solving by recurrence.

Let's think about the following equation. Let $\mathbb{E}(i)$ be the mathematical expectation when the input is $i$; then, by the linearity of mathematical expectation, we can easily derive the following equation:
$$
\mathbb{E}(i) =\frac {\mathbb{E}(1) + 1}{i} + \frac {\mathbb{E}(2) + 1}{i} + \frac {\mathbb{E}(3) + 1}{i} + \frac {\mathbb{E}(4) + 1}{i} + \dots + \frac {\mathbb{E}(i) + 1}{i}
$$

And in this problem, we know that $\mathbb{E}(1) = 0$. So let's transform the formula into:
$$
\mathbb{E}(i) = \frac {\mathbb{E}(1) + \mathbb{E}(2) + \dots + \mathbb{E}(i - 1) + i}{n - 1}
$$
This way we can work out the formula by recurrence.

Mathematical expectation is a common concept in OI, and mastering it helps a lot. I suggest readers go and read the relevant materials themselves; I won't describe it any further here.
