# How to prove that variance of number of successes in n Bernoulli trials has the largest value when probabilities are all equal?

Let S be the number of successes in n independent Bernoulli trials, with possibly different probabilities $p_1, ..., p_n$ on different trials. Show that for fixed $\mu=E(S)$, $Var(S)$ is largest in case the probabilities are all equal.

I figured out that $Var(S)=\sum_{i=1}^n p_i(1-p_i)$, and my question is why $p_i$ for i=1,2,..,n are all equal to make $Var(S)$ largest.

Thanks!

By Cauchy-Schwarz, we have $$\mu=p_1+\cdots+p_n\leq \sqrt{n}\Big[\sum_ip_i^2\Big]^{\frac{1}{2}}$$ with equality when $(p_1,\cdots,p_n)$ and $(1,\cdots,1)$ are linearly dependent, i.e. when all of the $p_i$ are equal.
This means that for $\mu$ fixed, $\sum_ip_i^2$ is minimized when all of the $p_i$ are equal, and since $$\mathrm{var}(S)=\sum_ip_i(1-p_i)=\mu-\sum_{i}p_i^2$$ it follows that $\mathrm{var}(S)$ is maximized when all of the $p_i$ are equal.
You want to maximize $\text{Var}(S) = \sum_{i=1}^n p_i (1-p_i)$ subject to the constraints $\sum_{i=1}^n p_i = \mu$ and $0 \le p_i \le 1$, where of course you need $0 \le \mu \le n$ to have any chance of a solution. Note that the feasible region is convex and the objective is a concave function, so any critical point is a global maximum. All you need is to show that $(\mu/n, \ldots, \mu/n)$ is a local optimum. Using a Lagrange multiplier, we consider
$$F(p_1, \ldots, p_n) = \sum_{i=1}^n p_i (1-p_i) + \lambda \left(\mu - \sum_{i=1}^n p_i\right)$$ and compute that $\dfrac{\partial F}{\partial p_i} = 0$ when all $p_i = \mu/n$ and $\lambda = 1 - 2 \mu/n$.