← LibraryExpectation and VarianceEngineering · MathematicsLesson 73/385← PrevNext →
ArticlePublished 7 Aug 20263 min readBy Kevin Jogin

Engineering  /  Mathematics  — Discrete Probability

Expectation and Variance

Expectation, variance, their algebraic properties and their use in analysing randomised algorithms.

Page KV-MATH-0344Reading time 3 minReviewed 2026-08-07Author Kevin Jogin

Executive summary

Expectation is the weighted average of a random variable and is linear without qualification. Variance measures spread and is additive only under independence.

The asymmetry between these two facts governs how randomised algorithm analyses are structured.

Learning objectives

  1. Compute expectation and variance from a distribution.
  2. Apply linearity of expectation to sums of indicators.
  3. State the conditions for variance additivity.

01Expectation

Definition

Expectation

E[X] = Σ_s s · P(X = s), equivalently Σ_{ω} X(ω) P(ω).

Theorem

Linearity

E[aX + bY] = aE[X] + bE[Y] for all random variables X, Y on the same space and all constants a, b, with no independence assumption.

A frequently useful alternative form for a non-negative integer variable is the tail sum.

E[X] = Σ_{k ≥ 1} P(X ≥ k)   for X taking values in {0, 1, 2, ...}

This form is often easier to evaluate, because tail probabilities are what an algorithm analysis naturally produces — the probability that a loop runs at least k times.

02Variance

Definition

Variance and standard deviation

Var[X] = E[(X − E[X])²] = E[X²] − E[X]².

The standard deviation is √Var[X], in the same units as X.

Variance rules
PropertyStatementCondition
ScalingVar[aX] = a²Var[X]Always
TranslationVar[X + c] = Var[X]Always
AdditivityVar[X+Y] = Var[X]+Var[Y]X, Y uncorrelated
Sum of n termsVar[ΣXᵢ] = ΣVar[Xᵢ]Pairwise independent

03Standard distributions

  1. Bernoulli(p)E = p, Var = p(1−p)A single indicator; the atom of most analyses
  2. Binomial(n,p)E = np, Var = np(1−p)Successes in n independent trials
  3. Geometric(p)E = 1/p, Var = (1−p)/p²Trials until first success; unbounded
  4. Uniform on 1..nE = (n+1)/2, Var = (n²−1)/12Random index selection

The geometric distribution is the one that appears whenever an algorithm repeats until success — random prime generation, rejection sampling, finding a quadratic non-residue. Its expectation 1/p is what converts a per-trial success probability into an expected running time.

04Frequently asked questions

Why use E[X²] − E[X]² rather than the definition?

Because it needs only two moments and both are usually easier to compute directly, especially for sums of indicators where the square expands into pairwise products that pairwise independence handles.

Does a finite expectation guarantee finite variance?

No. Distributions with heavy tails can have finite mean and infinite variance. For the bounded variables arising from terminating algorithms the question does not arise, but it matters for unbounded loops.

Is expected running time the right measure?

It is the standard one but it hides tail behaviour. An algorithm with good expectation may still be slow with uncomfortable probability, which is why concentration inequalities are applied on top rather than instead.

Sources and method

Structural reference: Victor Shoup, A Computational Introduction to Number Theory and Algebra, Version 1, Cambridge University Press, 2005 — book pages 111-117.

This page carries the durable method layer only: definitions, constructions, algorithms, complexity results and selection criteria, authored originally for KEVOS. No text is transcribed or paraphrased from the source, and no numeric tables or benchmark data are reproduced — these are routed to live authoritative sources instead.

Author: Kevin Jogin. Last reviewed 2026-08-07.

Continue learning

Random VariablesArticle · MathematicsNEXT LESSON →Markov's and Chebyshev's InequalitiesArticle · MathematicsConditional Probability and IndependenceArticle · MathematicsThe Birthday ParadoxArticle · Mathematics