Computing Basic Probabilities
You'll learn: How to calculate the probability of an event using the fundamental ratio formula.
Now that you understand sample spaces and events, it's time to actually compute probabilities. The most basic approach uses a beautifully simple ratio:
Probability = (Number of favorable outcomes) / (Total number of possible outcomes)
This formula applies when all outcomes in your sample space are equally likely—meaning each has the same chance of occurring.
The Core Idea
Think of rolling a fair six-sided die. The sample space is {1, 2, 3, 4, 5, 6}—six total outcomes. If you want to find the probability of rolling an even number, your event is {2, 4, 6}—three favorable outcomes.
P(even) = 3/6 = 1/2 or 0.5 or 50%
Another Example
Suppose you're testing a random number generator that produces integers from 1 to 100. What's the probability it generates a number divisible by 10?
- Total outcomes: 100 (the numbers 1 through 100)
- Favorable outcomes: 10 (the numbers 10, 20, 30, ..., 100)
- Probability: 10/100 = 0.1 or 10%
In Computer Science Context
When analyzing algorithms that make random choices (like randomized quicksort picking a pivot), this ratio helps us reason about expected behavior. If an algorithm randomly selects one element from an array of size n, and k elements would lead to good performance, the probability of choosing well is k/n.
Key Takeaway: To compute basic probability, count the favorable outcomes, count the total outcomes, and divide the first by the second—but only when all outcomes are equally likely.