# Conditional Probability

### [Conditional Probability](https://en.wikipedia.org/wiki/Conditional_probability)

This is defined as the probability of an event occurring, assuming that one or more other events have already occurred. Two events, $$A$$ and $$B$$ are considered to be *independent* if event $$A$$ has no effect on the probability of event $$B$$ (i.e. $$P(B \vert A) = P(B)$$). If events $$A$$ and $$B$$ are *not independent*, then we must consider the probability that both events occur. This can be referred to as the *intersection* of events $$A$$ and $$B$$, defined as $$P(A \cap B) = P(B \vert A) \* P(A)$$. We can then use this definition to find the *conditional probability* by dividing the probability of the intersection of the two events $$(A \cap B)$$ by the probability of the event that is assumed to have already occurred (event $$A$$):

$$\large P(B \vert A)=\frac{P(A \cap B)}{P(A)}$$

### [Bayes' Theorem](https://en.wikipedia.org/wiki/Bayes%27_theorem)

Let $$A$$ and $$B$$ be two events such that $$P(A \vert B)$$ denotes the probability of the occurrence of $$A$$ given that $$B$$ has occurred and $$P(B \vert A)$$ denotes the probability of the occurrence of  $$B$$given that $$A$$ has occurred, then:

$$\large P(A \vert B) = \frac{P(B \vert A) \* P(A)}{P(B)} = \frac{P(B \vert A) \* P(A)}{P( B \vert A) \* P(A) + P(B \vert A^c) \* P(A^c)}$$

<div align="left"><img src="/files/-LMsFA9UJjj79tESga8M" alt=""></div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stephanosterburg.gitbook.io/scrapbook/math/hackerrank/conditional-probability.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
