Introduction

Probability measures how likely an uncertain outcome is, on a scale from 0 to 1. Impossible events have probability 0 and the certain event has probability 1; in general these values mean almost never/almost surely, not necessarily an empty/full event. In computer science it is used to analyse randomised algorithms (expected running time of quicksort with a random pivot), hashing (collision probability), networks (packet loss, collision in shared media), reliability of systems, and machine learning. The topics set up the language: experiments, sample spaces, events, the axioms, and the rules that follow from them, including the difference between mutually exclusive and independent events. Conditional probability and random variables build directly on it.

Prerequisites

  • Sets: union, intersection, complement, De Morgan's laws, inclusion-exclusion.
  • Counting: permutations, combinations, complements.

Core concepts

Experiment, sample space, events

  • A random experiment is a procedure with a well-defined set of possible results whose actual result is uncertain (tossing a coin, rolling a die, measuring a response time).
  • The sample space SS (also Ω\Omega) is the set of all possible outcomes. Tossing two coins: S={HH,HT,TH,TT}S = \{HH, HT, TH, TT\}.
  • An event is a subset of SS. It occurs if the outcome lies in it. ∅\emptyset is the impossible event, SS the certain event.
  • Set operations give new events: A∪BA \cup B ("AA or BB"), A∩BA \cap B ("AA and BB"), AcA^c ("not AA"), A−BA - B ("AA but not BB").
  • AA and BB are mutually exclusive (disjoint) if A∩B=∅A \cap B = \emptyset. Events A1,…,AnA_1, \ldots, A_n are exhaustive if A1∪⋯∪An=SA_1 \cup \cdots \cup A_n = S. Nonempty mutually exclusive and exhaustive events form a partition of SS.

The axioms of probability

A probability assigns to each event AA a number P(A)P(A) such that:

  1. P(A)≥0P(A) \ge 0 for every event AA;
  2. P(S)=1P(S) = 1;
  3. for pairwise mutually exclusive events A1,A2,…A_1, A_2, \ldots (finite or countably infinite), P(A1∪A2∪⋯ )=P(A1)+P(A2)+⋯P(A_1 \cup A_2 \cup \cdots) = P(A_1) + P(A_2) + \cdots.

Everything else is derived from these three axioms (Kolmogorov).

Consequences

RuleStatement
ComplementP(Ac)=1−P(A)P(A^c) = 1 - P(A)
Impossible eventP(∅)=0P(\emptyset) = 0
MonotonicityA⊆B⇒P(A)≤P(B)A \subseteq B \Rightarrow P(A) \le P(B)
Range0≤P(A)≤10 \le P(A) \le 1
Addition ruleP(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B)
DifferenceP(A−B)=P(A)−P(A∩B)P(A - B) = P(A) - P(A \cap B)
Exactly one of A,BA, BP(A)+P(B)−2P(A∩B)P(A) + P(B) - 2P(A \cap B)
Three eventsP(A∪B∪C)=∑P(A)−∑P(A∩B)+P(A∩B∩C)P(A \cup B \cup C) = \sum P(A) - \sum P(A \cap B) + P(A \cap B \cap C)
Union bound (Boole)P(A1∪⋯∪An)≤P(A1)+⋯+P(An)P(A_1 \cup \cdots \cup A_n) \le P(A_1) + \cdots + P(A_n)
BonferroniP(A∩B)≥P(A)+P(B)−1P(A \cap B) \ge P(A) + P(B) - 1

The three-event rule is inclusion-exclusion; the sums run over the three events and the three pairs.

Classical (equally likely) probability

If SS is finite and every outcome is equally likely,

P(A)=∣A∣∣S∣=number of favourable outcomesnumber of possible outcomes.P(A) = \frac{|A|}{|S|} = \frac{\text{number of favourable outcomes}}{\text{number of possible outcomes}} .

The equally likely assumption must be justified by the set-up (fair coin, fair die, random selection). Sums of two dice are not equally likely: P(sum=7)=6/36P(\text{sum} = 7) = 6/36 but P(sum=2)=1/36P(\text{sum} = 2) = 1/36. Choose the sample space so that its outcomes are equally likely (ordered pairs of dice), then count.

When outcomes are not equally likely, P(A)P(A) is the sum of the probabilities of the outcomes in AA.

Sampling with and without replacement

Drawing kk items from NN, of which KK are "special":

  • Without replacement: P(exactly j special)=(Kj)(N−Kk−j)(Nk)P(\text{exactly } j \text{ special}) = \dfrac{\binom{K}{j}\binom{N-K}{k-j}}{\binom{N}{k}} (the hypergeometric probability).
  • With replacement: draws are independent with success probability p=K/Np = K/N, so P(exactly j)=(kj)pj(1−p)k−jP(\text{exactly } j) = \binom{k}{j} p^j (1-p)^{k-j} (binomial; see Discrete Distributions).

Independence

Events AA and BB are independent if

P(A∩B)=P(A) P(B).P(A \cap B) = P(A)\, P(B).

Intuitively, knowing that BB occurred does not change the probability of AA (made precise with conditional probability). Facts:

  • If AA and BB are independent, so are AA and BcB^c, AcA^c and BB, AcA^c and BcB^c.
  • ∅\emptyset and SS are independent of every event.
  • Events A1,…,AnA_1, \ldots, A_n are mutually independent if P(⋂i∈IAi)=∏i∈IP(Ai)P(\bigcap_{i \in I} A_i) = \prod_{i \in I} P(A_i) for every subset II of indices with ∣I∣≥2|I| \ge 2. Pairwise independence (only ∣I∣=2|I| = 2) is weaker.
  • For mutually independent events, P(at least one occurs)=1−∏i(1−P(Ai))P(\text{at least one occurs}) = 1 - \prod_i (1 - P(A_i)).

Mutually exclusive versus independent

These are different ideas; keep them apart.

Mutually exclusiveIndependent
DefinitionA∩B=∅A \cap B = \emptysetP(A∩B)=P(A)P(B)P(A \cap B) = P(A)P(B)
Depends on the probabilities?No (a set property)Yes
P(A∪B)P(A \cup B)P(A)+P(B)P(A) + P(B)P(A)+P(B)−P(A)P(B)P(A) + P(B) - P(A)P(B)
Can both hold?Only if P(A)=0P(A) = 0 or P(B)=0P(B) = 0Only if P(A)=0P(A) = 0 or P(B)=0P(B) = 0

If P(A)>0P(A) > 0 and P(B)>0P(B) > 0 and A,BA, B are mutually exclusive, then P(A∩B)=0≠P(A)P(B)P(A \cap B) = 0 \ne P(A)P(B): such events are dependent (if one happens, the other cannot).

Sample space, events, mutually exclusive versus independent
Figure 1. Left: the 36 outcomes of two dice as a 6 by 6 grid, with the events "sum is 7" and "first die shows 1" outlined; they are independent. Right: two disjoint events of positive probability, which are dependent.

Geometric probability

When an outcome is a point chosen uniformly from a region (an interval, a square), probability is a ratio of lengths or areas:

P(A)=length or area of Alength or area of S.P(A) = \frac{\text{length or area of } A}{\text{length or area of } S} .

For two independent numbers X,YX, Y, each uniform on [0,1][0, 1], the pair (X,Y)(X, Y) is uniform on the unit square, so every event about XX and YY is a region of that square and its probability is the region's area. Points and lines have area 0, so P(X=Y)=0P(X = Y) = 0 and it does not matter whether an inequality is strict.

Worked examples

Example 1: two dice

Two fair dice. AA = "sum is 7", BB = "first die is 1", CC = "sum is 8". P(A)=6/36=1/6P(A) = 6/36 = 1/6, P(B)=1/6P(B) = 1/6, P(A∩B)=1/36=P(A)P(B)P(A \cap B) = 1/36 = P(A)P(B): independent. P(C)=5/36P(C) = 5/36, P(B∩C)=0P(B \cap C) = 0 (the second die would need 7): BB and CC are mutually exclusive, hence dependent.

Example 2: at least one

A system has 4 independent components, each failing with probability 0.1 during a day. P(at least one fails)=1−0.94=1−0.6561=0.3439P(\text{at least one fails}) = 1 - 0.9^4 = 1 - 0.6561 = 0.3439.

Example 3: birthday problem

kk people, birthdays independent and uniform over 365 days (ignore leap years). P(all distinct)=365⋅364⋯(365−k+1)365kP(\text{all distinct}) = \dfrac{365 \cdot 364 \cdots (365 - k + 1)}{365^k}. For k=23k = 23, P(some shared birthday)≈0.5073P(\text{some shared birthday}) \approx 0.5073, just above 1/21/2. The same calculation bounds hash collisions: inserting kk keys into mm slots gives a collision with probability about 1−e−k(k−1)/(2m)1 - e^{-k(k-1)/(2m)}.

Example 4: drawing cards

Two cards drawn without replacement from a standard 52-card deck. P(both aces)=(42)/(522)=6/1326=1/221P(\text{both aces}) = \binom{4}{2}/\binom{52}{2} = 6/1326 = 1/221. With replacement: (4/52)2=1/169(4/52)^2 = 1/169.

Example 5: pairwise but not mutually independent

Toss two fair coins. AA = "first is H", BB = "second is H", CC = "the two coins differ". Each has probability 1/21/2, and each pair intersects in one outcome of probability 1/41/4: pairwise independent. But A∩B∩C=∅A \cap B \cap C = \emptyset, so P(A∩B∩C)=0≠1/8P(A \cap B \cap C) = 0 \ne 1/8: not mutually independent.

Example 6: addition rule

P(A)=0.5P(A) = 0.5, P(B)=0.4P(B) = 0.4, P(A∪B)=0.7P(A \cup B) = 0.7. Then P(A∩B)=0.5+0.4−0.7=0.2=P(A)P(B)P(A \cap B) = 0.5 + 0.4 - 0.7 = 0.2 = P(A)P(B), so A,BA, B are independent, and P(exactly one)=0.5+0.4−0.4=0.5P(\text{exactly one}) = 0.5 + 0.4 - 0.4 = 0.5.

Example 7: meeting problem

Two friends arrive independently at uniformly random times between 5:00 and 6:00, and each waits 15 minutes for the other. Measure time in hours after 5:00, so X,YX, Y are uniform on [0,1][0, 1] and they meet if ∣X−Y∣≤1/4|X - Y| \le 1/4. The complement is two corner triangles of the unit square with legs 3/43/4, of total area (3/4)2=9/16(3/4)^2 = 9/16. So P(meet)=1−9/16=7/16=0.4375P(\text{meet}) = 1 - 9/16 = 7/16 = 0.4375. With a waiting time ww (as a fraction of the window), P(meet)=1−(1−w)2P(\text{meet}) = 1 - (1 - w)^2. In the same square, P(X+Y≤1)=1/2P(X + Y \le 1) = 1/2 (a half-square triangle).

Example 8: divisibility by inclusion-exclusion

A number is drawn uniformly from {1,…,1000}\{1, \ldots, 1000\}. Let AdA_d be "divisible by dd"; the count of multiples of dd is ⌊1000/d⌋\lfloor 1000/d \rfloor. Then ∣A2∣=500|A_2| = 500, ∣A3∣=333|A_3| = 333, ∣A5∣=200|A_5| = 200, ∣A2∩A3∣=∣A6∣=166|A_2 \cap A_3| = |A_6| = 166, ∣A10∣=100|A_{10}| = 100, ∣A15∣=66|A_{15}| = 66, ∣A30∣=33|A_{30}| = 33, and

∣A2∪A3∪A5∣=1033−332+33=734,P=0.734.|A_2 \cup A_3 \cup A_5| = 1033 - 332 + 33 = 734, \qquad P = 0.734 .

The events are not independent here: P(A2)P(A3)=0.1665≠P(A2∩A3)=0.166P(A_2)P(A_3)=0.1665\ne P(A_2\cap A_3)=0.166. Always test independence by P(A∩B)=P(A)P(B)P(A\cap B)=P(A)P(B). For divisibility events with pairwise coprime divisors, a uniform consecutive-integer range whose length is divisible by their product is a sufficient, not necessary, shortcut for independence.

Example 9: taking turns

AA and BB toss a fair coin alternately, AA first, and the first head wins. AA wins on toss 1, 3, 5, and so on:

P(A wins)=12+(12)3+(12)5+⋯=1/21−1/4=23.P(A \text{ wins}) = \frac12 + \left(\frac12\right)^3 + \left(\frac12\right)^5 + \cdots = \frac{1/2}{1 - 1/4} = \frac23 .

The game ends with probability 1, so P(B wins)=1/3P(B\text{ wins})=1/3. In general, independent trials with common success probability 0<p≤10<p\le1, and q=1−pq=1-p, give first-player win probability p/(1−q2)=1/(2−p)p/(1-q^2)=1/(2-p). For a die and “first six wins”, this is 6/116/11. At p=0p=0, both win probabilities are zero and nontermination has probability one.

Example 10: matching letters and envelopes

nn letters go into nn addressed envelopes at random. Let AiA_i be "letter ii is in its own envelope". Any kk of these events occur together with probability (n−k)!/n!(n - k)!/n!, and there are (nk)\binom{n}{k} such groups, so inclusion-exclusion gives

P(no letter in its own envelope)=∑k=0n(−1)kk!  →  e−1≈0.3679(n→∞).P(\text{no letter in its own envelope}) = \sum_{k=0}^{n} \frac{(-1)^k}{k!} \;\to\; e^{-1} \approx 0.3679 \quad (n \to \infty).

For n=4n = 4: 1−1+12−16+124=924=381 - 1 + \frac12 - \frac16 + \frac1{24} = \frac{9}{24} = \frac38 (9 of the 24 permutations are derangements), so at least one letter is correct with probability 5/85/8. The limit 1−e−1≈0.6321 - e^{-1} \approx 0.632 is reached quickly: already for n=6n = 6 the value is 0.63190.6319.

Important properties and observations

  • Probabilities of a partition add to 1; this is the quickest consistency check on an answer.
  • "At least one" is almost always computed as 1 minus "none".
  • Independence is a property of the probability assignment, not of the events as sets; it cannot be read off a Venn diagram.
  • Zero probability does not mean impossible for continuous outcomes (any single exact value of a continuous measurement has probability 0).
  • P(A∪B)≤P(A)+P(B)P(A \cup B) \le P(A) + P(B) always, with equality if and only if P(A∩B)=0P(A \cap B) = 0.
  • Identical objects. Outcomes must be equally likely before counting. Put 2 identical balls into 2 boxes, each ball independently choosing either box with probability 1/2: the patterns (2,0)(2, 0), (1,1)(1, 1), (0,2)(0, 2) have probabilities 1/4,1/2,1/41/4, 1/2, 1/4, not 1/31/3 each. Label the objects, count, then forget the labels.
  • The triple product alone is not enough. With 8 equally likely outcomes, A={1,2,3,4}A = \{1, 2, 3, 4\}, B={1,5,6,7}B = \{1, 5, 6, 7\}, C={1,2,3,5}C = \{1, 2, 3, 5\} satisfy P(A∩B∩C)=1/8=P(A)P(B)P(C)P(A \cap B \cap C) = 1/8 = P(A)P(B)P(C), yet P(A∩B)=1/8≠1/4P(A \cap B) = 1/8 \ne 1/4. Mutual independence of three events needs all four product equations.

GATE examination perspective

  • Counting-based probability. Build an equally likely sample space (ordered outcomes, labelled objects), then count favourable outcomes.
  • Union and complement. Inclusion-exclusion for two or three events; complements for "at least one".
  • Independence checks. Compare P(A∩B)P(A \cap B) with P(A)P(B)P(A)P(B); check all subsets for mutual independence.
  • Trap: treating mutually exclusive events as independent, or the reverse.
  • Trap: using ∣A∣/∣S∣|A|/|S| on a sample space whose outcomes are not equally likely (sums of dice, numbers of heads).
  • Geometric probability. Two uniform numbers on [0,1][0, 1]: draw the unit square and compute areas (meeting problems, X+Y≤tX + Y \le t).
  • Alternating turns and matching. A geometric series for "first to succeed wins"; inclusion-exclusion for "nobody gets their own".
  • Trap: counting patterns of identical objects as if they were equally likely.

Summary

Sources

  1. S. Ross, A First Course in Probability, 8th ed., Pearson Prentice Hall, 2010: Chapter 2 (Axioms of Probability) and Section 3.4 (Independent Events).

Next steps