Course contentsShow
← Computer Science
Lesson 133 of 2,8723. Probability for Computer ScienceFree lesson

Variance: Measuring Spread

Understand variance as the expected squared deviation from the mean, quantifying outcome variability.

Variance: Measuring Spread

You'll learn: How variance quantifies how much random outcomes differ from their expected value.

Why Expected Value Isn't Enough

You already know how to compute the expected value of a random variable—it tells you the "center" or average outcome. But two random variables can have the same expected value yet behave very differently. Imagine two algorithms: one always takes exactly 10ms, another takes either 1ms or 19ms (averaging 10ms). Both have E[X] = 10, but the second is far more unpredictable. We need a way to measure this spread or variability.

What is Variance?

Variance measures how far outcomes tend to deviate from the mean. Formally, for a random variable X with expected value μ = E[X]:

Var(X) = E[(X - μ)²]

In plain English: variance is the expected value of the squared deviations from the mean.

Why squared? Because deviations can be positive or negative (some values above the mean, some below). Squaring ensures all deviations are positive and penalizes larger deviations more heavily.

Computing Variance

For a discrete random variable:

Var(X) = Σ (xᵢ - μ)² · P(X = xᵢ)

There's also a computational shortcut: Var(X) = E[X²] - (E[X])²

This is often easier to calculate—find the expected value of X², then subtract the square of the expected value of X.

Why It Matters in CS

Variance helps analyze algorithm performance consistency, network jitter, load balancing fairness, and randomized algorithm reliability. Low variance means predictable behavior; high variance means outcomes are scattered.

Key Takeaway: Variance measures outcome spread by computing the expected squared distance from the mean, quantifying a random variable's unpredictability.