# Probability theory: The Law Of Total Probability

This is part of the course “Probability Theory and Statistics for Programmers”.

Let it be required to determine the probability of the event A, which can occur with one of the events *H1, H2,…, Hn* forming a complete group of mutually exclusive events. This is **“The Law Of Total Probability”:**

In order to show how this concept works, we will represent events like a tree. Let’s imagine that we want to calculate the probability of some event *A1*.

Let’s calculate the probability of the event *A1 *using the previous formula:

Now we can write a function which will take the tree of probabilities and name of the event and will return probability. We will represent root as the list of trees and will walk recursively through those trees calculating probability on the way.

Reach the next level of focus and productivity with increaser.org.