Olympiad in Informatics

Mathematical Expectation and Its Linearity

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

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.