For my combinatorics homework I have the following problem:
Let $A = \{a_1, a_2, ..., a_m\}$ and $B = \{b_1, b_2, ... , b_n\}$ with $m \geq n$. Show that the amount of surjective functions $f$ from $A$ to $B$ is equal to: \begin{equation} \sum_{i=0}^n (-1)^i {n \choose i} (n-i)^m \end{equation}
My first thought was that, because these functions must be surjective, for every element $b \in B$ there must be a unique $a \in A$ such that $f(a) = b$. Therefore we must choose $n$ elements in $A$ that have a unique image on $B$ and the rest of the elements in $A$ can be sent to a random element in $B$. So i was thinking about: \begin{equation} {m \choose n} \cdot n! \cdot n^{m-n} \end{equation} as the amount of all possible surjective functions $f$ from $A$ to $B$.
My second thought was that the combination is unnecessary and therefore the formula must be:
\begin{equation} n! \cdot n^{m-n} \end{equation} Is this correct? If so, how can i prove that this is the same as the summation given at the beginning?
I hope anybody can help me with this problem.
Thanks in advance!