Table of contents
1.
Introduction
2.
Conditional Probability
3.
Law of total probability
3.1.
Derivation of the law of total probability
4.
FAQs
5.
Key Takeaways
Last Updated: Mar 27, 2024
Easy

Law of total probability

Author HET FADIA
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this article, we learn about the law of total probability. The law of total probability is used to express the total probability as the sum of several distinct events.

To brush up on your knowledge of random variables and probability,  you can read the article introduction to random variables and probability on Coding Ninjas Studio.

Before we see the law of total probability, let us first understand conditional probability.

Conditional Probability

Conditional probability is the likelihood of an event based on the occurrence of the previous event.

P(A|B) means the probability of A event when event B has occurred.

The formula for the conditional probability is given by P(A|B) = P(A  B) / P(B).

Let us see the law of total probability in the next section.

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) (B ∩ A2)(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(AB) =  Φ.

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!

Live masterclass