bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Data Interview Question

Even Heads with 21 Fair Coins

bugfree Icon

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

Solution & Explanation

Problem Statement: You have 21 fair coins, each flipped once. What is the probability of obtaining an even number of heads?

Understanding the Problem:

  • We have 21 fair coins, which means the probability of getting a head or a tail on each flip is 0.5.
  • We need to find the probability that the number of heads is even after flipping all 21 coins.

Key Insight: The probability of getting an even number of heads is equal to the probability of getting an odd number of heads. This is due to the symmetric nature of the binomial distribution when the probability of success (getting a head) is 0.5.

Mathematical Explanation:

  1. Binomial Distribution:

    • The number of heads in 21 flips follows a binomial distribution with parameters n=21n = 21 and p=0.5p = 0.5.

    • The probability of getting exactly kk heads is given by:

      P(k)=(21k)(0.5)k(0.5)21k=(21k)(0.5)21P(k) = \binom{21}{k} \cdot (0.5)^k \cdot (0.5)^{21-k} = \binom{21}{k} \cdot (0.5)^{21}

  2. Even vs Odd Heads:

    • We are interested in the sum of probabilities for even kk: 0, 2, 4, ..., 20.

    • By symmetry, the sum of probabilities for odd kk: 1, 3, 5, ..., 21 is the same as for even kk.

    • The total probability for all possible outcomes (even and odd) is 1, so:

      P(even)+P(odd)=1P(\text{even}) + P(\text{odd}) = 1

    • Since P(even)=P(odd)P(\text{even}) = P(\text{odd}), it follows that:

      2P(even)=1    P(even)=0.52 \cdot P(\text{even}) = 1 \implies P(\text{even}) = 0.5

  3. Verification through Binomial Expansion:

    • Using the binomial theorem, the expansion of (1+x)21(1 + x)^{21} gives:

      (1+x)21=k=021(21k)xk(1 + x)^{21} = \sum_{k=0}^{21} \binom{21}{k} x^k

    • Setting x=1x = 1 gives the sum of all probabilities (equal to 2^21).

    • Setting x=1x = -1 and adding gives the sum of coefficients for even kk:

      (1+1)21+(11)21=221+0=2even k(21k)(1 + 1)^{21} + (1 - 1)^{21} = 2^{21} + 0 = 2 \cdot \sum_{\text{even } k} \binom{21}{k}

    • Dividing by 2 gives the sum of probabilities for even kk, confirming P(even)=0.5P(\text{even}) = 0.5.

Conclusion:

  • The probability of obtaining an even number of heads when flipping 21 fair coins is 0.5.
  • This result is intuitive because the distribution of heads is symmetric around its mean, and the number of heads can equally likely be even or odd.