How many surjective function from a set of 3 elements to a set of 2 elements

combinatoricsdiscrete mathematicsfunctions

I know there are many questions like this.

but I need a detailed explanation to the answer of this question:
"How many surjective functions from a set of 3 elements to one of 2 elements?"

I ask yet another question of this type because I was asked this question in my discrete math exam, and my (wrong) answer was:

$$2^3 -2$$
where $2^3$ is the total number of function (because I have 2 possible choices for each element of the first set) where I need to subtract the number of possible functions that can't be surjective that is 2, because taking as an example the two sets:
$$\{1,2,3\} \text{ and } \{A,B\}$$
and these 2 functions:
$$f(1) \to A \\f(2) \to B$$ the third element $3$ cannot "go" either in A nor in B, so the two unpossible surjective functions are $2$.

However that's wrong (or at least my explanation).
My professor told me that it is not the right motivation and that I do not understand what a function is, now I have to retake the exam and I need to know in detail what I should have said, thanks to those who will help me.

Best Answer

Take $A=\{1,2,3\}$ and $B=\{a,b\}$. Then there are 2 possibilities for $f(1)$. Then, if $f(2)=f(1)$, there is 1 possibility for $f(3)$ and if $f(2)\neq f(1)$, there are 2 possibilities for $f(3)$. So, you have $2\cdot (1+ 2)=6$ possibilities.

Related Question