I was asked a "simple" question by one of my students in the tutorial class, but I found myself struggling with this for about 2 hours already. Here is the question:
Assume there are $K$ constants: $0\leq C_{1}<C_{2}<...<C_{K-1}<C_{K}\leq1$; Let $X$ be a random variable with $Pr(X=C_{k})=\frac{1}{K}$, $k=1,...,K$. Find when the maximum of $Var(X)$ is attained, determine the value of $K$ and the value of $(C_{1},...,C_{K})$ when this happens.
Here are some of my ideas:
$E[X]=\sum_{k=1}^{K}C_{k}\frac{1}{K}=\frac{1}{K}\sum_{k=1}^{K}C_{k}$
$E[X^2]=\sum_{k=1}^{K}(C_{k})^2\frac{1}{K}=\frac{1}{K}\sum_{k=1}^{K}(C_{k})^2$
$Var(X)=E[X^2]-(E[X])^2=\frac{1}{K^2}\big(K\sum_{k=1}^{K}(C_{k})^2-(\sum_{k=1}^{K}C_{k})^2\big)\\~~~~~~~~~~~~=\frac{1}{K^2}\big((K-1)\sum_{k=1}^{K}(C_{k})^2-2\sum_{i\neq j}C_{i}C_{j}\big)$.
I am really wondering if it is possible to apply Lagrange multiplier method to this.
Any help and advice will be sincerely appreciated. Thank you very much in advance!
Let's first of all allow some of the $C$s to be equal.
The derivative of the variance w.r.t. $C_i$ is $\frac2K(C_i-m)$ where $m$ is the expectation of $X$ = the mean of the $C$s. Therefore, pushing any $C_i$ away from $m$ increases the variance, so a maximum-variance configuration has all the $C$ equal to either 0 or 1.
If it has $p$ 0s and $q$ 1s then the variance is $\frac{pq}{(p+q)^2}$ which, for fixed $p+q=K$, is biggest when $p,q$ are as close as possible.
So the biggest variance you can get is when "half" of the $C$s are 0 and "half" are 1. (If $K$ is odd, one of those groups will be 1 larger than the other.)
This maximum isn't attained, if you keep the restriction that all the $C$ have to be unequal. But you can get as close to it as you like by pushing "half" the values very close to (one another and to) 0 and the rest very close to (one another and to) 1.
(You didn't ask about this, but the minimum happens when all the $C$ are equal; this too isn't attained if you require them to be distinct but you can get as close as you like by making all the values very close together.)