How to solve this or simplify? $\displaystyle \sum_{k=0}^{n}\binom{n}{k}k^2p^k(1-p)^(n-k)$
Start with the binomial expansion $\displaystyle (p+q)^n = \sum_{k=0}^{n}\binom{n}{k}p^kq^{n-k}.$ Differentiate partially with respect to p (keeping q constant), then multiply both sides by p. That will give $\displaystyle np(p+q)^{n-1} = \sum_{k=0}^{n}\binom nk kp^kq^{n-k}.$ Now do the same thing again: $\displaystyle np(p+q)^{n-1} + n(n-1)p^2(p+q)^{n-2} = \sum_{k=0}^{n}\binom nk k^2p^kq^{n-k}.$ Finally, put $\displaystyle q=1-p$ to get $\displaystyle \sum_{k=0}^{n}\binom{n}{k}k^2p^k(1-p)^{n-k} = np+n(n-1)p^2.$