## Law of total probability

Given n mutually exclusive events A1, A2, â€¦ An such that the sum of their probability is 1 and the union of the events is event space E, then the law of total probability is given by

P(B) = P(B|A1) x P(A1) + P(B|A2) x P(A2) + â€¦ P(B|An) x P(An)

where B is an arbitrary event in the event space E.

In other words, given n events A1, A2, A3 .. An such that P(Ai) âˆ© P(Aj) = Î¦ and the sum of their probabilities, i.e. P(A1) + P(A2) + .. P(An) = 1 and the union of their event space is event space E then the law of total probability can be applied on them.

### Derivation of the law of total probability

Given that the union of the events A1, A2 â€¦ An is E. Thus

A1 U A2 U A3 â€¦ U An = E

As B is a random event in the event space E, we can write

B = B âˆ© E

Replacing E with A1 U A2 U A3 â€¦ U An, we get

B = B âˆ© (A1 U A2 U A3 â€¦ U An)

Applying distribution law, we get

B = (B âˆ© A1) U (B âˆ© A2) U (B âˆ© A3) â€¦ U (B âˆ© An)

Now each event Ai and Aj are mutually exclusive for every i, not equal to j. Thus every event B âˆ© Ai and B âˆ© Aj are mutually exclusive.

Thus we can rewrite the above probability formula as

P(B) = P(B âˆ© A1) U P(B âˆ© A2) U P(B âˆ© A3) â€¦ U P(B âˆ© An)

From the conditional probability, we have

P(B|A) = P(B âˆ© A)/P(A)

Thus

P(B|A) x P(A) = P(B âˆ© A)

Substituting the values of P(B âˆ© Ai) we get

P(B) = P(B | A1) x P(A1) U P(B | A2) x P(A2) U P(B | A3) x P(A3) â€¦ U P(B | An) x P(An)

Thus we derived the law of total probability.

Example

Q. We draw two cards from a pack of shuffled cards with replacement. What is the probability that the second drawn card is a king?

Solution:

Let P(B) be the probability such that the second card drawn is a king.

Then there are two possible outcomes.

The first card is a king and the second card is a king.

The first card is not a king, but the second card is a king.

Thus P(B) = P(B|A1) P(A1)+P(B|A2) P(A2)

P(A1) = probability such the first card is a king.

P(A2) = probability such the first card is not a king.

P(B|A1) = probability of the second card is king such that the first card was a king

P(B|A2) = probability of the second card is king such that the first card was not a king

P(A1) = 4/52 = 1/13

P(A2) = 48/52 = 12/13

P(B|A1) = 4/52 = 1/13

P(B|A2) = 4/52 = 1/13

Thus P(B) = 1/13 x 1/13 + 12/13 x 1/13

Thus P(B) = 1/4

Check out this problem - __Subarray Sum Divisible By K__

## FAQs

**1. What does probability mean?**

The probability is the measure of which an event is likely to occur. The probability of an event A is denoted by P(A). The probability of an event is greater than or equal to 0 and less than or equal to 1. Thus 0<= P(A) <=1.

**2. What are mutually exclusive events?**

The events which do not occur at the same time are known as mutually exclusive events. If A and B are mutually exclusive events, then P(Aâˆ©B) = Î¦.

**3. What is Conditional probability?**

Conditional probability is the likelihood of an event based on the occurrence of the previous event. The formula for the conditional probability is given by P(A|B) = P(A âˆ© B) / P(B).

**4. What is the law of total probability?**

The law of total probability is used to express the total probability as the sum of several distinct events.

**5. What is the formula for the law of total probability?**

Given n mutually exclusive events A1, A2, â€¦ An such that the sum of their

probability is 1 and the union of the events is event space E, then the law of total probability is given by P(B) = P(B|A1) x P(A1) + P(B|A2) x P(A2) + â€¦ P(B|An) x P(An) where B is an arbitrary event in the event space E.

## Key Takeaways

We have extensively discussed the law of total probability.

We hope that this blog has helped you enhance your knowledge regarding the law of total probability, and if you would like to learn more, check out our articles and archives on cyber security:

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses and refer to the mock test and problems available, Take a look at the interview experiences and interview bundle for placement preparations.

Do upvote our blog to help other ninjas grow.

Happy Learning!