# Maximizing Probability: Series of Games Played

Two friends are playing games. This series of games are independent. Player 1 has a probability of $p$ of winning each game, and Player 2 has $1-p$ probability of winning each game. The winner is the first one to win $k$ games.

Now, if $k=4$, what is the probability that $7$ games were played in total? What is the maximum probability of this occurring? What is $p$ when the probability is maximized?

First you need to notice that for a total of $7$ games being played, you would need to have the first 6 games being won 3 times by player 1 and 3 times by player 2. Otherwise, you would necessarily have less than 7 games being played.

Now you have two scenarios. Player 1 is the winner or player 2 is the winner. If player 1 is the winner, it would amount to the sequences for which the last winner is player 1, and the first six is divided 3 by 3 among the two. The chances that the first 6 are divided can be found considering the following logic. Let's say the first three is won by player 1 and the last three by player 2. Then the probability of this sequence is equal to $$p^3(1-p)^3$$ However, there are different sequences that might yield the same outcome. Example would be the first 2 and the 4th being won by player 1, which is also going to give us a probability of $$p^3(1-p)^3.$$ So how many of these sequences can we encounter? Basically it is equivalent to the number of ways of choosing 6 balls in a row where 3 of them are white and 3 of them are black. These permutations would have the size of $$\frac{6!}{3!3!}$$ where we need to divide by $3!$ each because of the balls being identical (or wins being identical).

Therefore, the chances that the first 6 are divided equally is $$\frac{6!}{3!3!}p^3(1-p)^3.$$

Now, the chances that the last one is won by player 1 is $p$ thus, the chances that p1 wins in 7 trials is $$\frac{6!}{3!3!}p^3(1-p)^3\times p = \frac{6!}{3!3!}p^4(1-p)^3.$$ Similarly the chances that player 2 wins is when we have it multiplied by $(1-p)$, which is equal to $$\frac{6!}{3!3!}p^3(1-p)^3\times(1- p) = \frac{6!}{3!3!}p^3(1-p)^4.$$ Hence, the total probability is equal to $$\frac{6!}{3!3!}(p^4(1-p)^3 + p^3(1-p)^4) = \frac{6!}{3!3!}p^3(1-p)^3(p + (1-p)) = \frac{6!}{3!3!}p^3(1-p)^3.$$

This probability is maximized when the function $$\frac{6!}{3!3!}p^3(1-p)^3$$ is maximized. To make things easy, we can take a monotonic transformation of this function (let's forget about the constant in the beginning). Let's exponentiate the whole function to $1/3$ to get $(p^3(1-p)^3)^{1/3}=p(1-p) = p - p^2$. Take derivative w.r.t. $p$ to get the first order condition $1-2p=0$. Hence, $p=1/2$ maximizes this probability.

If k=4 and 7 games were played in total, that means each player has to win 3 games in the first 6 games (otherwise the the game would end before the 7th round). Then no matter who wins the 7th round, the game will end.

So the probability is $Pr =(1-p)^{3}(p)^{3}=-p^6+3p^5-3p^4+p^3$.

To find where the probability is maximized, take the derivative of Pr with respect to p:

$\frac{dPr}{dp}=-6p^5+15p^4-12p^3+3p^2$

Set this to zero:

$-6p^5+15p^4-12p^3+3p^2=0$

By solving this equation, we get three solutions: $p=0, \frac{1}{2},1$.

$Pr=0$ when $p=0,1$ and $Pr=\frac{1}{64}$ when $p=\frac{1}{2}$.

Therefore Pr is maximized at $p=\frac{1}{2}$ and its value is $\frac{1}{64}$.