Data Interview Question

Coin Bias from Consecutive Heads

bugfree Icon

Hello, I am bugfree Assistant. Feel free to ask me for any question related to this problem

Solution & Explanation: Determining Coin Bias from Consecutive Heads

Problem Restatement

You have two coins:

  • Coin 1 (Fair Coin): Probability of heads = 0.5, Probability of tails = 0.5
  • Coin 2 (Biased Coin): Probability of heads = 0.75, Probability of tails = 0.25

You randomly select one of these coins and flip it twice, resulting in two heads. We need to determine the probability that the coin you picked is the fair one.

Approach

This is a classic problem that can be solved using Bayes' Theorem, which allows us to update our probability estimates based on new evidence.

Bayes' Theorem: P(AB)=P(BA)×P(A)P(B)P(A|B) = \frac{P(B|A) \times P(A)}{P(B)}

Where:

  • P(AB)P(A|B) is the probability of event AA given event BB has occurred.
  • P(BA)P(B|A) is the probability of event BB given event AA has occurred.
  • P(A)P(A) is the prior probability of event AA.
  • P(B)P(B) is the total probability of event BB.

Definitions

  • Event A: Selecting the fair coin.
  • Event B: Obtaining two heads in a row.

Calculations

  1. Prior Probability of Selecting the Fair Coin (P(A)):

    • Since there are two coins, the probability of selecting the fair coin is P(A)=12P(A) = \frac{1}{2}.
  2. Probability of Two Heads Given the Coin is Fair (P(B|A)):

    • For a fair coin, the probability of heads on one flip is 0.50.5.
    • Therefore, P(BA)=0.5×0.5=0.25P(B|A) = 0.5 \times 0.5 = 0.25.
  3. Total Probability of Getting Two Heads (P(B)):

    • If the fair coin is selected, P(BA)=0.25P(B|A) = 0.25 with a probability of 12\frac{1}{2}.
    • If the biased coin is selected, the probability of two heads is 0.75×0.75=0.56250.75 \times 0.75 = 0.5625 with a probability of 12\frac{1}{2}.
    • P(B)=(12×0.25)+(12×0.5625)=0.125+0.28125=0.40625P(B) = \left( \frac{1}{2} \times 0.25 \right) + \left( \frac{1}{2} \times 0.5625 \right) = 0.125 + 0.28125 = 0.40625.
  4. Probability the Coin is Fair Given Two Heads (P(A|B)):

    • Using Bayes' Theorem: P(AB)=0.25×0.50.40625=0.1250.406250.3077P(A|B) = \frac{0.25 \times 0.5}{0.40625} = \frac{0.125}{0.40625} \approx 0.3077
    • Simplifying gives 413\frac{4}{13}.

Conclusion

The probability that the selected coin is fair, given that both flips resulted in heads, is 413\frac{4}{13} or approximately 0.3077. This reflects the reduced likelihood of the fair coin being the one used, given the observed outcome of two heads.