Study guide: Probability
Overview
Discrete probability deals with a finite or countable set of outcomes. When outcomes are equally likely, the probability of an event is the number of favorable outcomes divided by the total, so counting is the main tool.
Conditional probability, independence, Bayes' theorem and expectation extend this to reasoning when you have partial information.
Key ideas explained
Sample spaces and the basic rules
The sample space S is the set of all outcomes and an event is a subset. Probabilities satisfy 0 ≤ P(E) ≤ 1, P(S) = 1, P(E′) = 1 − P(E) and P(A ∪ B) = P(A) + P(B) − P(A ∩ B).
Conditional probability and independence
P(A | B) = P(A ∩ B) / P(B). Events are independent when P(A ∩ B) = P(A)·P(B), equivalently P(A | B) = P(A). Independent is not the same as mutually exclusive: two mutually exclusive events with positive probability are always dependent.
Bayes' theorem
P(A | B) = P(B | A)·P(A) / P(B), where P(B) = P(B | A)·P(A) + P(B | A′)·P(A′). It reverses the direction of conditioning, and it shows why the base rate of A matters.
Expectation and variance
E[X] = Σ x·P(x). Expectation is linear: E[X + Y] = E[X] + E[Y] even when X and Y are dependent. Var(X) = E[X²] − (E[X])². A fair die has E = 3.5 and Var = 35/12.
Worked examples
Counting outcomes with two dice
Problem. Find P(sum = 8) for two fair dice, and P(sum = 8 | first die is 3).
- There are 36 equally likely outcomes.
- Sum 8 occurs for (2,6), (3,5), (4,4), (5,3), (6,2): five outcomes.
- If the first die is 3, the second must be 5, which is one of the six equally likely values.
Answer. P(sum = 8) = 5/36 and P(sum = 8 | first = 3) = 1/6.
Bayes' theorem and the base rate
Problem. A condition affects 1% of people. A test is positive for 95% of those who have it and for 5% of those who do not. What is P(condition | positive)?
- Numerator: 0.95 × 0.01 = 0.0095.
- P(positive) = 0.95 × 0.01 + 0.05 × 0.99 = 0.0095 + 0.0495 = 0.059.
- Divide: 0.0095 / 0.059 ≈ 0.161.
Answer. About 16.1%. Most positive results are false alarms because the condition is rare.
Enter these same values in the calculator above and compare each step with the working shown here.
Common mistakes to avoid
- Base-rate neglect: treating P(positive | condition) as if it were P(condition | positive).
- Multiplying probabilities of events that are not independent.
- The gambler's fallacy: past independent outcomes do not change the next one.
- Equating “mutually exclusive” with “independent”.
- Adding probabilities of overlapping events without subtracting the intersection.
Where this shows up in computer science
- Naive Bayes classifiers, used in spam filtering, apply Bayes' theorem to word frequencies.
- Randomized algorithms and hashing are analysed with expected values, for example the expected number of collisions.
- Reliability engineering and A/B testing depend on independence and conditional probability.
Test yourself
Try each question before opening the answer.
What is the probability of at least one head in 3 fair coin flips?
1 − (1/2)³ = 7/8.
What is the expected value of a fair six-sided die?
3.5.
If P(A) = 0.4, P(B) = 0.5 and A, B are independent, what is P(A ∪ B)?
0.4 + 0.5 − 0.4·0.5 = 0.7.