Sum of squares of terms of a binomial expansion I have a coin that show heads with a probability $p$. I toss it $N$ times and count the number of heads. I repeat the experiment once more. What's the probability that I get the same number of heads as before?
Using the binomial expansion, the probability of getting $k$ heads is ${N\choose k} p^k (1-p)^{N-k}$. So the probability of getting the same number of heads in the two independent experiments is $\sum_k {N\choose k}^2 p^{2k} (1-p)^{2N-2k}$, or the sum of squares of all terms in a binomial expansion. Can somebody help me calculate this analytically?

I think you might be able to follow this route ($q=1-p$):


*

*$\sum_k {N\choose k} (xp)^k (1-p)^{N-k}=(xp+q)^n$

*$f(z)=(zp+q)^n(\frac{p}{z}+q)^n$ has your sum $\sum_k {N\choose k}^2 p^{2k} (1-p)^{2N-2k}$ as the free term (no $z$)

*Your sum is the integral $\frac{1}{2\pi i}\int\frac{f(z)}{z}dz$ over the unit circle.

*$z=e^{2\pi i t}$ reduces the integral to $\int_0^{2\pi}f(e^{2\pi i t})dt$

