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
- E[X] = Σ x p(x).
- For g(X): E[g(X)] = Σ g(x) p(x). Do not compute g(E[X]).
- In general E[X²] ≠ (E[X])².
- Compare strategies by comparing their expected payoffs.
- 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.
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²]?
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.