Sample Space and Events
Probability Foundations
The Building Blocks of Every Probability Problem
Every probability question starts with a simple question: what can possibly happen? Sample spaces and events give you the language to describe the unknown — and once you can describe it, you can measure it.
Key things this concept helps with:
- Defining outcomes — Enumerate every possible result of a random experiment
- Grouping outcomes into events — Work with subsets that match conditions you care about
- Combining events with set operations — Use union, intersection, and complement to build complex scenarios from simple ones
Master this, and every probability formula that follows will make intuitive sense.
What You'll Learn
- 1List a sample space for finite, countable and continuous experiments
- 2Decide when outcomes are equally likely and why the representation matters
- 3Translate word problems into unions, intersections and complements
- 4Apply the probability axioms and read a Venn diagram as arithmetic
What is a Sample Space?
Definition
The sample space is the set of all possible outcomes of a random experiment. Each outcome is called a sample point. The sample space is the foundation upon which probability is built.
A sample space is complete (nothing possible is left out) and mutually exclusive (no two outcomes occur at once), and the representation you choose decides whether the arithmetic that follows is easy or treacherous. For two dice, listing the 36 ordered pairs keeps every outcome equally likely, so a probability is a count divided by 36. Listing the 21 possible sums instead looks simpler, but those sums are not equally likely — a sum of 7 arises in six ways while a sum of 2 arises in one — so counting favourable sums and dividing by 21 gives the wrong answer. The sample space must be built so that equal counts mean equal likelihood.
import numpy as np
import matplotlib.pyplot as plt
# Common sample spaces
coin_sample_space = {'Heads', 'Tails'}
die_sample_space = {1, 2, 3, 4, 5, 6}
card_sample_space = [f"{rank} of {suit}"
for suit in ['Hearts', 'Diamonds', 'Clubs', 'Spades']
for rank in ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']]
print(f"Coin: {coin_sample_space}")
print(f"Die: {die_sample_space}")
print(f"Cards: {len(card_sample_space)} outcomes")
# Two dice as ordered pairs: 36 equally likely points
dice = [(a, b) for a in range(1, 7) for b in range(1, 7)]
print(f"\nTwo dice: {len(dice)} ordered outcomes")
print(f"Sum >= 10: {[p for p in dice if sum(p) >= 10]}")
print(f"P(sum >= 10) = {sum(1 for p in dice if sum(p) >= 10)}/{len(dice)}")
Experiments fall into three shapes. A fair coin or a defect count gives a finite space; the number of customers arriving in an hour gives a countably infinite space of 0, 1, 2, …; and a measured length or a waiting time gives an uncountable space such as the interval from 0 to 1. The counting formula only applies to finite spaces whose points are equally likely, which is why continuous spaces need intervals and lengths instead of tallies.
Events
An event is any subset of the sample space.
| Event Type | Definition | Example (Die) |
|---|---|---|
| Simple event | Single outcome | {3} |
| Compound event | Multiple outcomes | {2, 4, 6} (even) |
| Impossible event | Empty set ∅ | {7} |
| Certain event | Entire sample space S | {1,2,3,4,5,6} |
Because an event is just a subset, the number of possible events is the number of subsets: a space of size supports events, including the empty set and the space itself. Rolling a die therefore admits events, 63 of them non-empty, and every probability question is a statement about which of those 64 subsets you are interested in.
The Probability Axioms
Probability is a function that assigns a number to each event, and only three rules govern the assignment:
- Non-negativity: for every event .
- Certainty: , because something in the sample space must happen.
- Additivity: if two events are mutually exclusive, .
Everything practical follows from those three lines. The empty event has probability 0, the complement rule comes from additivity applied to and its complement, and monotonicity gives . None of the axioms mention counting — the equally-likely shortcut is a convenience layered on top, not a foundation.
Set Operations
These three operations generate every event you will ever need: differences, subsets and symmetric differences are all built from them. Python's set type implements them directly, so a quick simulation can confirm a hand calculation before you trust it.
| Operation | Set builder | English | Python | Probability reading |
|---|---|---|---|---|
| Union | x in A or in B | at least one occurs | A.union(B) | P(A) + P(B) − P(A ∩ B) |
| Intersection | x in A and in B | both occur | A.intersection(B) | P(A ∩ B) |
| Complement | x in S, not in A | A fails | S - A | 1 − P(A) |
| Difference | x in A, not in B | A without B | A.difference(B) | P(A) − P(A ∩ B) |
| Symmetric difference | x in exactly one | one but not both | A.symmetric_difference(B) | P(A) + P(B) − 2P(A ∩ B) |
# Set operations for probability
S = {1, 2, 3, 4, 5, 6} # Die sample space
A = {1, 2, 3} # Event A: outcome ≤ 3
B = {2, 4, 6} # Event B: even number
union = A | B # A ∪ B
intersection = A & B # A ∩ B
complement_A = S - A # A^c
difference = A - B # A \ B
symmetric = A ^ B # A Δ B
print(f"S = {S}")
print(f"A = {A}, B = {B}")
print(f"A ∪ B = {union}")
print(f"A ∩ B = {intersection}")
print(f"A^c = {complement_A}")
print(f"A \\ B = {difference}")
print(f"A Δ B = {symmetric}")
# Read probabilities straight off the sets, assuming equally likely points
p = lambda ev: len(ev) / len(S)
print(f"\nP(A) = {p(A)}, P(B) = {p(B)}")
print(f"P(A ∪ B) = {p(union)} (addition rule: {p(A)} + {p(B)} - {p(A & B)})")
print(f"P(A ∩ B) = {p(intersection)}")
Two identity checks are worth memorising because they catch most bookkeeping errors: De Morgan's law says the complement of a union is the intersection of the complements, written , and distributivity lets an intersection spread across a union, .
Worked Examples
Venn Diagram Visualization
fig, ax = plt.subplots(figsize=(8, 6))
# Draw Venn diagram
from matplotlib.patches import Circle
c1 = Circle((0.35, 0.5), 0.3, alpha=0.3, color='blue', label='A')
c2 = Circle((0.65, 0.5), 0.3, alpha=0.3, color='red', label='B')
ax.add_patch(c1)
ax.add_patch(c2)
ax.text(0.2, 0.5, 'A only', ha='center', va='center', fontsize=12)
ax.text(0.5, 0.5, 'A ∩ B', ha='center', va='center', fontsize=12)
ax.text(0.8, 0.5, 'B only', ha='center', va='center', fontsize=12)
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_aspect('equal')
ax.set_title('Venn Diagram: Events A and B')
ax.axis('off')
plt.savefig('venn-diagram.png', dpi=150)
plt.show()
The diagram is arithmetic you can see: the two circles are partitioned into three regions — only, only, and the lens where they overlap — and adding the three region counts must reproduce the union. If your numbers do not close, the overlap has been counted twice or omitted.
Sample Space in Machine Learning
| ML Application | Sample Space Usage | Why |
|---|---|---|
| Classification | Sample space = all classes | Model outputs must cover all outcomes |
| Generation models | Sample space = data distribution | GANs, diffusion models generate from space |
| Reinforcement learning | Sample space = states/actions | MDP framework |
import numpy as np
from sklearn.datasets import load_iris
# Sample space concept in classification
iris = load_iris()
sample_space = set(iris.target_names)
print(f"Sample space (Iris classification): {sample_space}")
print(f"All possible outcomes: {list(sample_space)}")
print(f"Model must output probabilities for ALL outcomes in sample space")
A classifier's output layer is a probability vector over the label space, so its softmax scores must be non-negative and sum to 1 — precisely the axioms above, applied to the sample space of classes. A prediction for a label outside that space, or a vector whose entries do not total 1, is a violation of the model's own sample space definition rather than a mere numerical glitch.
Frequently Asked Questions
Does the sample space have to list outcomes that are equally likely?
Only if you intend to compute probability by counting. Equal likelihood is a property you engineer into the representation — ordered pairs for dice, ordered draws for cards — and when outcomes carry different weights you must attach those weights to the points instead of dividing counts by the size of the space.
Why does a single point in a continuous sample space have probability zero?
Because probability for continuous spaces is defined by length or area over intervals, and a point has zero length. This does not mean the point is impossible: the sample space contains uncountably many points, exactly one of which will be observed.
Can a sample space contain an event with probability zero?
Yes, and it is called a null event — for a continuous space, any single value is null, and for a discrete space it is the empty set or an outcome assigned weight zero. Null events are possible yet occur with probability zero, a distinction that matters once conditional probability on continuous variables enters the picture.
How is an event different from an outcome?
An outcome is one point of the sample space; an event is a set of outcomes, which may be a single point, several points, or the entire space. Probability is only ever assigned to events, never to raw outcomes in isolation.
Common Mistakes
Dividing favourable outcomes by the size of a sample space whose points are not equally likely
Fix: Rebuild the space so points are equiprobable — ordered pairs instead of sums for dice — or attach explicit weights to each point.
Listing outcomes that can occur together as separate sample points
Fix: Sample points must be mutually exclusive; if two descriptions can both be true of one result, they are one outcome, not two.
Adding probabilities of events that overlap
Fix: Subtract the intersection: P(A ∪ B) = P(A) + P(B) − P(A ∩ B), which reduces to plain addition only when the events are disjoint.
Key Takeaways
- The sample space is the complete, mutually exclusive list of what an experiment can produce, and the representation you choose decides whether outcomes are equally likely
- An event is any subset of that space; n sample points support 2ⁿ events, including the impossible event and the certain event
- Only three axioms are needed: probabilities lie in [0,1], the whole space has probability 1, and disjoint events add
- Union, intersection and complement are implemented directly by Python set operators, so a hand calculation can always be checked by enumeration
- Continuous spaces replace counting with measure: points have probability zero, intervals carry the mass
Interview Questions
Q1: Define a sample space for rolling two dice and state how many events it has.
The 36 ordered pairs of faces, each equally likely. Since there are 36 points, the space supports 2 to the power 36 events — about 68.7 billion subsets, each of which is a possible event.
Q2: Why can't you list the sums 2 through 12 as equally likely outcomes?
The sums are not equiprobable: 7 can be made six ways, 2 only one way. Counting favourable sums out of 11 would misassign probability, so the space must be built from ordered pairs instead.
Q3: What do the probability axioms guarantee that counting does not?
They work for non-uniform and continuous spaces: non-negativity, certainty of the whole space, and additivity for disjoint events. Counting is just the special case where every point carries the same weight.
Q4: You need P(at least one six in four rolls). How does the complement help?
Instead of enumerating the overlap-heavy union, compute 1 minus the probability of no six at all: 1 − (5/6)⁴ ≈ 0.5177. The complement turns a union problem into a single product.
Probability begins with counting — and set theory is the language that lets you count with precision.