Conditional Probability
You'll learn: How to calculate the probability of one event happening when you already know another event has occurred.
What Is Conditional Probability?
Imagine you're debugging code and you know a crash occurred. What's the probability it was caused by a memory leak given that the crash happened? This is conditional probability — the likelihood of event A when event B has already happened.
When you learn that one event has occurred, it changes your sample space. You're no longer considering all possibilities, just the ones where the known event is true.
The Formula
The conditional probability of event A given event B is written as P(A|B) (read as "probability of A given B") and calculated as:
P(A|B) = P(A ∩ B) / P(B)
provided that P(B) > 0.
This says: "Take the probability that both A and B occur, and divide by the probability that B occurs."
Why It Works
Think of P(B) as your new universe — you're only looking at cases where B happened. Within that restricted universe, P(A ∩ B) represents the portion where A also occurs. Dividing by P(B) rescales everything to make the probabilities add up to 1 in this smaller universe.
Simple Example
A program has two types of errors: syntax (S) and logic (L). Suppose 30% of runs have errors, 10% have both types, and you know an error occurred. What's the probability it includes a logic error?
P(L|error) = P(L ∩ error) / P(error) = 0.10 / 0.30 = 1/3
Key Takeaway: Conditional probability P(A|B) = P(A ∩ B) / P(B) updates probabilities based on new information, narrowing the sample space to only outcomes where B has occurred.