I was trying to calculate the number of surjective (onto) functions from A to B.
Let a set $A$ contain $m$ elements and another set $B$ contain $n$ element i.e.
$$|A|=m, \quad |B|=n.$$
Now, if $n>m$, no. of onto functions is $0$.
When $m \ge n$,
since there should be no unrelated element in B, let us relate first n elements of a A to B,so that all elements of B gets related.
Hence total possibility for first n elements of A( which actually contain m elements ) is
$$n!$$
Now the remaining $m-n$ elements in $A$ can be related to any of the $n$ elements of $B$. Hence the total possibility of the remaining $m-n$ elements of $B$ is
$$n^{m-n}$$
Therefore total number of surjective function is$$n!*n^{m-n}$$
Is anything wrong in this calculation ?If its wrong ,can anyone suggest correct method with proof.
Combinatorics – Number of Surjective Functions from a Set with $m$ Elements onto a Set with $n$ Elements
combinationscombinatoricsfunctionspermutations
Best Answer
In general computing the number of surjections between finite sets is difficult.
Your procedure for obtaining the figure of $n! \cdot n^{m-n}$ is overcounting, and also erroneous for another reason.
Even computing the number of surjections $A \to B$ when $n(A)=m$ and $n(B)=3$ is pretty tricky. There are $3^m - 3 \cdot 2^m + 3$ of them (see here, for instance).
If I recall correctly, there is no known closed form expression for the number of surjections from a set of size $m$ to a set of size $n$.