Question involving functions and permutations If $A=\{1,2,3,4\},B=\{a,b,c\}$, how many functions $A\to B$ are not onto? 
My Try: so one element in $B$ shouldn't have a preimage in A so one element is excluded(for convenience) so for $4$ elements in $A$ there are $2$ in B hence total ways are $16$ then $2$ elements in $B$ don't have a pre image so $2^3$ ways. Thus total ways are $16+8=24$ . So this can be done for all $3$ elements. Hence total ways are $72$ but answer given is $45$
 A: Let us denote a function using notation where
 $(abcc)$ corresponds to $f(1)=a, f(2)=b, f(3)=c, f(4)=c$
The number of ALL functions would be $3^4=81$
The number of functions which are Onto would be counting something like $(aabc), (bcba), ...$
There are $3$ choices to choose the duplicated alphabet, and $4!/2!=12$ ways to rearrange them, meaning $3*12=36$ onto functions exist.
Thus, there are $81-36=45$ non-onto functions.
A: A method more in line with how you seem to have been thinking:
For a function to not be onto, there must be at least one letter which is absent in the image.
Let $X_a$ be the functions where $a$ is absent in the image (among possibly others too), $X_b$ be the functions where $b$ is absent in the image (among possibly others too), $X_c$ be the functions where $c$ is absent in the image (among possibly others too).
The set of functions where at least one of these are absent in the image are then $X_a\cup X_b\cup X_c$
We count:  $|X_a\cup X_b\cup X_c| = |X_a|+|X_b|+|X_c|-|X_a\cap X_b|-|X_a\cap X_c|-|X_b\cap X_c|+|X_a\cap X_b\cap X_c|$ via inclusion exclusion principle.
We have $|X_a|= 2^4$ since for each element of $A$, we have two options for where to send it (either $b$ or $c$ since it can't be sent to $a$).  Similarly $|X_b|=|X_c|=2^4$
We have $|X_a\cap X_b|=1^4$ since for each element of $A$, we have only one option for where to send it (only $c$ since it can't be sent to either of $a$ or $b$).  Similarly $|X_a\cap X_c|=|X_b\cap X_c|=1$
Finally, note that $|X_a\cap X_b\cap X_c|=0$ since it is impossible for a function to avoid all of the codomain as an image.
Our total then is $|X_a\cup X_b\cup X_c| = |X_a|+|X_b|+|X_c|-|X_a\cap X_b|-|X_a\cap X_c|-|X_b\cap X_c|+|X_a\cap X_b\cap X_c|\\=16+16+16-1-1-1=45$ functions which are not onto.
A: You overcounted the "one element excluded" mappings
(assuming they were supposed to be "exactly one element excluded").
Yes, there are $16$ ways to map $A$ onto the two remaining elements of $B$
after one element of $B$ is excluded, but if you exclude $a$ (for example),
then two of the mappings you produce in this way are the one that
maps everything to $b$ and the one that maps everything to $c$.
So if you take your $16$ mappings and multiply by $3$, you have not only
already counted all the mappings that exclude two elements of $B$,
you have counted each of those mappings twice.
So the Inclusion-Exclusion Principle applies, and rather than add
the "two elements excluded" mappings, you should subtract them
from the total.
Moreover, there are not $2^3$ ways to map the elements of $A$ if
two elements of $B$ are excluded; there is only one way:
all elements of $A$ onto the one remaining element of $B$.
But there are three different elements of $B$ that might be the
one remaining, so there are a total of $3$ mappings excluding two elements.
In conclusion,
$$ 48 - 3 = 45 $$
is the correct answer.
An alternative is to remove the "only one element of $B$" mappings from
the "one element excluded" mappings, so instead of $16$ mappings,
you have only the $14$ mappings that actually use both remaining
elements of $B$.
Then you can compute the total number of mappings as
$$ (14 \cdot 3) + 3 = 42 + 3 = 45. $$
