During a question concerning the Birthday Paradox, given P is the number of pairs of people with the same birthday in a group of 20 people and assuming there are 365 possible birth-days, I am to compute the variance. My problem is computing $E[P^2]$. What my teacher did is: The number of pairs of pairs that have no common person is ${20\choose 2}\cdot {18\choose 2}$, the number of pairs of pairs that have precisely one person in common ${20\choose 2}\cdot 2\cdot 18$, hence $E[P^2]={20\choose 2}\cdot {18\choose 2}\cdot ({1\over 365})^2+{20\choose 2}\cdot 2\cdot 18\cdot ({1\over 365})^2+{20\choose 2}\cdot ({1\over 365})$.
What is the explanation for looking at pairs of pairs? What is the explanation of looking at pairs with no common persons? How does it follow the formula, if there is any, for computing $E[X^2]$? I will really appreciate any explanation of this or any explanation as for how to compute $E[X^2]$ for P or in general.
There are $n:=\binom{20}{2}$ pairs in total. Give each pair a number and let $P_i$ take value $1$ if the two persons of pair $i$ have the same birthday and let $P_i=0$ otherwise. This for $i=1,\dots,n$. The number of pairs having the same birthday equals: $$P=\sum_{i=1}^nP_i$$ and consequently $$P^2=\sum_{i=1}^n\sum_{j=1}^nP_iP_j$$ hence$$\mathbb EP^2=\sum_{i=1}^n\sum_{j=1}^n\mathbb EP_iP_j$$
By evaluating $\mathbb EP_iP_j=\mathbb P(P_i=P_j=1)$ three cases must be discerned: