Definition of Expected Value
You'll learn: How to calculate the average result you'd expect from a random variable if you ran it many, many times.
What Is Expected Value?
Expected value is the long-run average of a random variable. Imagine flipping a coin where heads gives you 0. If you flip it 1,000 times, you'd expect to average about 0.50—is the expected value.
It tells you what outcome to "expect" on average, even though any single trial might give you something different.
The Formula
For a discrete random variable X with possible values x₁, x₂, ..., xₙ, the expected value E(X) is:
E(X) = x₁·P(X = x₁) + x₂·P(X = x₂) + ... + xₙ·P(X = xₙ)
Or more compactly:
E(X) = Σ xᵢ · P(X = xᵢ)
You multiply each possible outcome by its probability, then sum everything up.
Example
Rolling a fair six-sided die:
- Each outcome (1, 2, 3, 4, 5, 6) has probability 1/6
- E(X) = 1·(1/6) + 2·(1/6) + 3·(1/6) + 4·(1/6) + 5·(1/6) + 6·(1/6)
- E(X) = 21/6 = 3.5
You'll never actually roll 3.5, but over many rolls, the average approaches 3.5.
Why It Matters
In computer science, expected value helps analyze algorithm performance (average case complexity), evaluate randomized algorithms, and predict outcomes in simulations or decision-making systems.
Key Takeaway: Expected value is the probability-weighted average of all possible outcomes—the number you'd expect "on average" over many repetitions.