← 📊 Random Variables, Expectation & Variance
Subtopic 3 of 6

3.3Expectation and E[g(X)]

The idea

The expected value is the long-run average: each value weighted by its probability. For a function of X, apply the function to the values first.

Think of it like this: The "fair price" of a lottery ticket: the average payout if you played endlessly.

Why it exists

Expectation is the basis of the next lessons (linearity, variance) and of average-case algorithm analysis.

How it works

  1. E[X] = Σ x p(x).
  2. For g(X): E[g(X)] = Σ g(x) p(x). Do not compute g(E[X]).
  3. In general E[X²] ≠ (E[X])².
  4. Compare strategies by comparing their expected payoffs.
  5. The expected value need not be a value X can take (3.5 for a die).

Worked example: GATE 2021: question A (80% right, 10 marks) and B (50% right, 20 marks)

A first: 0.8 × 10 + 0.8 × 0.5 × 20 = 16. B first: 0.5 × 20 + 0.5 × 0.8 × 10 = 14. So answer A first, expecting 16 marks.

Now play with it

  • →Load the fair-die preset and change g to X²: E[X²] = 91/6, not 3.5².
  • →Try the loaded preset 0, 1, 2, 5 and read E[X] and the variance.
0.1667
1
0.1667
2
0.1667
3
0.1667
4
0.1667
5
0.1667
6
E[X] = Σ x·p3.5
E[X²]15.1667
Var(X) = E[X²] − E[X]²2.9167
standard deviation1.7078
E[X²]15.1667
F(2) = P(X ≤ 2)0.3333

E[g(X)] = Σ g(x)·p(x): apply g to the values, not to the mean. Note E[X²] ≠ E[X]² in general; the gap is the variance. The CDF F(t) = P(X ≤ t) is a step function that climbs from 0 to 1 (GATE 2012: F(−1) = 0.5 and F(1) = 1).

Check yourself

X takes 0 with probability 0.5 and 4 with probability 0.5. What is E[X²]?

Remember: E[X] = Σ x p(x); E[g(X)] = Σ g(x) p(x), never g(E[X]) unless g is linear.
Exam notes (the dense version)

E[X] = Σ x p(x) (or ∫ x f(x) dx): the long-run average. For a function, E[g(X)] = Σ g(x) p(x): apply g to the values, not to the mean. In general E[g(X)] ≠ g(E[X]) (only for linear g). Also E[X] = Σ P(X > k) for a non-negative integer-valued X.

Previous year questions: Random Variables, Expectation & Variance (11)

PYQs are grouped by topic, so this is the full set for Random Variables, Expectation & Variance; try the ones that match this subtopic. Open all 11 on the topic page.