Prove the identity $\sum_{r=0}^n r^2 \binom {n}{r} p^r q^{n-r}=npq+n^2p^2$ when $p+q = 1$ 
If $p+q=1$, then show that $$\sum_{r=0}^n r^2 \binom {n}{r} p^r q^{n-r}=npq+n^2p^2.$$

I was able to solve this by differentiating the expression twice and then relating the given variables.
But the method turned out to be pretty tedious, moreover it took me a while to figure it out.
Is there any method I can employ to solve this?
 A: HINT:
As $r^2=r(r-1)+r,$
as $r(r-1)\binom nr=n(n-1)\cdot\dfrac{(n-2)!}{n(n-1)\cdot(r-2)!\cdot\{n-2-(r-2)\}!}=n(n-1)\binom{n-2}{r-2}$
Can you prove $$r^2\binom nr=n(n-1)\binom{n-2}{r-2}+n\binom{n-1}{r-1}$$
$$\implies\sum_{r=0}^nr^2\binom nrp^rq^{n-r}$$
$$=n(n-1)p^2\sum_{r=2}^n\binom{n-2}{r-2}p^{r-2}q^{n-2-(r-2)}+np\sum_{r=0}^n\binom{n-1}{r-1}p^{r-1}q^{n-1-(r-1)}$$
$$=n(n-1)p^2(p+q)^{n-2}+np(p+q)^{n-1}$$
A: The proof we sketch applies only to non-negative $p$ and $q$.
Let $X_1,X_2,\dots,X_n$ be independent Bernoulli random variables with $p$ the probability of success. Then their sum $Y$ has binomial distribution, and the sum we are trying to evaluate is $E(Y^2)$. 
To find $E(Y^2)$, expand $(X_1+X_2+\cdots +X_n)^2$ and use the linearity of expectation. When we expand, we get
$$\sum_1^n X_i^2 +2\sum_{i\lt j} X_iX_j.$$
Taking expectations, we get $np +n(n-1)p^2$. This is $np-np^2+n^2p^2$, or equivalently $npq+n^2p^2$.
A: If you know a bit of probability theory you'll recognize the sum in question is $E(X^2)$ where $X$ is a random variable with Binomial($n,p$) distribution. For such a variable we have $E(X)=np$ and $\operatorname{Var}(X)=np(1-p)=npq$, so
$$E(X^2)=\operatorname{Var}(X) + (EX)^2 = npq + (np)^2.$$
A: Given $$\sum^{n}_{r=0}r^2\binom{n}{r}p^r\cdot q^{n-r} = \sum^{n}_{r=0}\left(e^{rx}\right)''|_{x=0}\binom{n}{r}p^r\cdot q^{n-r}$$
$$ = \bigg(\sum^{n}_{r=0}(pe^x)^{r}q^{n-r}\bigg)''|_{x=0} = \bigg((pe^x+q)^{n}\bigg)^{''}|_{x=0}=.........$$
