I have the following question:
Prove $$ n2^{n-1} + n(n-1)2^{n-2} = \sum_{k=0}^{n} {n\choose k} k^2 $$
The best I could do was get to
$$ \sum_{k=0}^{n} {n\choose k} \frac{1}{n-k-1} + \sum_{k=0}^{n} {n\choose k} \frac{1}{(n-k-1)(n-k-2)}$$
I have the following question:
Prove $$ n2^{n-1} + n(n-1)2^{n-2} = \sum_{k=0}^{n} {n\choose k} k^2 $$
The best I could do was get to
$$ \sum_{k=0}^{n} {n\choose k} \frac{1}{n-k-1} + \sum_{k=0}^{n} {n\choose k} \frac{1}{(n-k-1)(n-k-2)}$$
Define
$$f(x)=(1+x)^n=\sum\limits_{k=0}^n{n\choose k}x^k$$
Then
$$f'(x)=n(1+x)^{n-1}=\sum\limits_{k=0}^nk{n\choose k}x^{k-1}$$
What do you get if you differentiate $xf'(x)$?
Foobaz' answer reminds me of another method.
$$k{n \choose k}=\frac{k\,n!}{k!(n-k)!}=\frac{n(n-1)!}{(k-1)!(n-k)!}=n{n-1\choose k-1}$$
Likewise:
$$k(k-1){n \choose k}=\frac{k(k-1)n!}{k!(n-k)!}=\frac{n(n-1)(n-2)!}{(k-2)!(n-k)!}=n(n-1){n-2\choose k-2}$$
Therefore
$$\sum_{k=0}^nk^2{n\choose k}=\sum_{k=2}^nk(k-1){n\choose k}+\sum_{k=1}^nk{n\choose k}\\ =\sum_{k=2}^nn(n-1){n-2\choose k-2}+\sum_{k=1}^nn{n-1\choose k-1}=n(n-1)2^{n-2}+n2^{n-1}$$
Note that $$ \sum_{k=0}^{n} {n\choose k} k^2=2\sum_{k=0}^n\binom{n}{k}\binom{k}{2}+ \sum_{k=0}^nk\binom{n}{k}\tag{0} $$ We claim that $$ \sum_{k=0}^nk\binom{n}{k}=n2^{n-1}.\tag{1} $$ Indeed both sides count tuples $(x,A)$ where $x\in A$ and $A\subset[n]$. The RHS chooses $x$ first ($n$ choices) and then we have $2^{n-1}$choices for the remaining elements of $A$ as $A\setminus x\subset [n]\setminus x$. The RHS classifies classifies $A$ based on its cardinality. If $|A|=k$, then there are $\binom{n}{k}$ choices for $A$ and then we can choose $x$ in $k$ ways. Sum over $k$ to get the result.
Next we claim that $$ \sum_{k=0}^n\binom{n}{k}\binom{k}{2}=\binom{n}{2}2^{n-2}.\tag{2} $$ Indeed both sides count tuples $(A, B)$ where $A\subset B\subset[n]$ and $|A|=2$ and can be reasoned similarly as in the previous paragraph.
It follows from $(0), (1)$ and $(2)$ that $$ \sum_{k=0}^{n} {n\choose k} k^2=n2^{n-1}+2\binom{n}{2}2^{n-2}= n2^{n-1}+n(n-1)2^{n-2} $$ as desired.