Skip to content
GATEiit

GATE CSE · Engineering Mathematics

Random variables

Discrete and continuous random variables: PMF, PDF and CDF, expectation and its linearity, variance and standard deviation, functions of a random variable, and joint distributions with independence.

Before you start

  • Basic probability →

    A random variable assigns numbers to outcomes; its probabilities come from the sample space.

  • Integration →

    For a continuous random variable, probabilities, means and variances are integrals of the PDF.

  • Counting →

    Discrete PMFs are often found by counting favourable outcomes.

This topic comes before: Mean, median, mode and standard deviation, Uniform, normal, exponential, Poisson and binomial distributions

Concept notes

1. Random variables, PMF, PDF and CDF

A random variable X is a function that gives a real number to each outcome of an experiment.

A discrete random variable takes countably many values. Its probability mass function (PMF) is p(x)=P(X=x), with p(x)≥0 and ∑xp(x)=1.

A continuous random variable has a probability density function (PDF) f(x)≥0 with ∫−∞∞f(x) dx=1 and P(a≤X≤b)=∫abf(x) dx. For a continuous X, P(X=a)=0 for every single point, so < and ≤ give the same probability. A PDF value can be greater than 1; only its total area must be 1.

The cumulative distribution function (CDF) F(x)=P(X≤x) works for both kinds. Properties:

  • F is non-decreasing and right-continuous,
  • F(−∞)=0 and F(∞)=1,
  • P(a<X≤b)=F(b)−F(a),
  • for continuous X, f(x)=F′(x); for discrete X, F is a step function with a jump of p(k) at each value k.

To find an unknown constant c in a PMF or PDF, set the total probability equal to 1.

1234 0.10.20.30.4 1234 0.10.30.61 PMF p(k) = k/10 CDF F(x): jumps of p(k) at each k
PMF $p(k) = \frac{k}{10}$ for $k = 1, 2, 3, 4$ (left) and its step-shaped CDF (right).

2. Expectation

The expectation (mean) of X is its probability-weighted average: E[X]=∑xx p(x)orE[X]=∫−∞∞xf(x) dx.

For a function g, use the distribution of X directly (no need to find the distribution of g(X)): E[g(X)]=∑xg(x) p(x)or∫g(x)f(x) dx.

Linearity: E[aX+b]=aE[X]+b, and E[X+Y]=E[X]+E[Y] always, even when X and Y are dependent.

Indicator trick: to find the expected number of events that happen, write the count as a sum of indicators Ij (1 if event j happens, else 0). Then E[Ij]=P(event j) and E[count]=∑jP(event j). This avoids finding the full distribution. For example, the expected number of empty boxes when n balls go independently and uniformly into n boxes is n(1−1n)n.

In general E[g(X)]≠g(E[X]). For instance E[X2]≥(E[X])2, and E[1X]≠1E[X] in general.

For a non-negative integer-valued X, E[X]=∑k≥1P(X≥k).

3. Variance and standard deviation

The variance measures spread about the mean: Var⁡(X)=E[(X−μ)2]=E[X2]−(E[X])2,μ=E[X]. The second form is the one to use in calculations. The standard deviation is σ=Var⁡(X), in the same units as X.

Rules:

  • Var⁡(X)≥0, and it is 0 only when X is a constant (with probability 1).
  • Var⁡(aX+b)=a2Var⁡(X): adding a constant does not change spread, and the sign of a disappears.
  • Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)+2Cov⁡(X,Y).
  • If X and Y are independent, Cov⁡(X,Y)=0 and Var⁡(X±Y)=Var⁡(X)+Var⁡(Y). Note the plus sign even for X−Y.
Quantity Discrete Continuous
E[X] ∑x p(x) ∫xf(x) dx
E[X2] ∑x2p(x) ∫x2f(x) dx
Var⁡(X) E[X2]−(E[X])2 same

Work in fractions where you can; rounding E[X] before squaring causes errors in the variance.

4. Joint distributions and independence

For two discrete random variables the joint PMF is p(x,y)=P(X=x,Y=y). The marginal PMFs come from summing out the other variable: pX(x)=∑yp(x,y),pY(y)=∑xp(x,y). For continuous variables, replace the sums by integrals of the joint PDF f(x,y).

X and Y are independent when p(x,y)=pX(x) pY(y) for every pair (x,y) (or f(x,y)=fX(x)fY(y)). One failing cell is enough to show dependence.

Covariance: Cov⁡(X,Y)=E[XY]−E[X]E[Y], where E[XY]=∑x,yxy p(x,y).

If X and Y are independent:

  • E[XY]=E[X] E[Y],
  • Cov⁡(X,Y)=0,
  • E[g(X)h(Y)]=E[g(X)] E[h(Y)].

The converse is false: zero covariance does not imply independence. If X is −1,0,1 with equal probability and Y=X2, then E[XY]=E[X3]=0=E[X]E[Y], so the covariance is 0, yet Y is fully determined by X.

Conditional PMF: P(X=x∣Y=y)=p(x,y)pY(y) when pY(y)>0.

Formulas to remember

Total probability
∑xp(x)=1,∫−∞∞f(x) dx=1
CDF
F(x)=P(X≤x),P(a<X≤b)=F(b)−F(a)
Expectation
E[X]=∑xx p(x)=∫xf(x) dx
Variance
Var⁡(X)=E[X2]−(E[X])2
Linear transformation
E[aX+b]=aE[X]+b,Var⁡(aX+b)=a2Var⁡(X)
Variance of a sum
Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)+2Cov⁡(X,Y)
Covariance
Cov⁡(X,Y)=E[XY]−E[X] E[Y]
Tail sum for expectationFor X taking values 0,1,2,…
E[X]=∑k≥1P(X≥k)

Common mistakes

  • Writing Var(aX + b) = a·Var(X) or keeping the b; the correct result is a² Var(X).
  • Using Var(X − Y) = Var(X) − Var(Y) for independent variables; the variances add.
  • Assuming E[g(X)] = g(E[X]) for a non-linear g such as x² or 1/x.
  • Treating zero covariance as independence.
  • Forgetting to normalise a PDF or PMF before computing the mean.
  • Rounding E[X] before computing E[X²] − (E[X])², which spoils the variance.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Mean and variance from a PMF

numerical

P(X=k)=ck for k=1,2,3,4. Find c, E[X] and Var⁡(X).

  1. Step 1: Use total probability to find c.

    Try it on paper first.

Example 2: A continuous random variable

numerical

X has PDF f(x)=kx2 for 0≤x≤3 and 0 elsewhere. Find k, E[X] and P(X≤1).

  1. Step 1: Normalise the PDF.

    Try it on paper first.

Example 3: Expected number of empty boxes

numerical

Three balls are placed independently, each into one of three boxes chosen uniformly at random. Find the expected number of empty boxes.

  1. Step 1: Write the count as a sum of indicators.

    Try it on paper first.

Example 4: Is E[1/X] equal to 1/E[X]?

conceptual

X is 1 or 2 with probability 12 each. Compare E[1X] with 1E[X].

  1. Step 1: Compute E[1/X] using the distribution of X.

    Try it on paper first.

Previous year questions

12 official GATE CSE questions on this topic, newest first.

Practise these 12 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.