How many nonsurjective functions $f: A \to A$ are there if $A=\{1,2,3,4,5\}$

combinatoricsfunctions

I saw some duplicates, but all are from $A$ to $B$ with other groups of numbers and I can't match it to mine.

How many nonsurjective functions $f: A \to A$ are there if $A=\{1,2,3,4,5\}$?

The answer is $3005$. Question is, how do I get to it?

I wanted to try to understand it, so I wanted to know if there is any formula to calculate the surjective functions and from there, I can somehow calculate the nonsurjective functions myself and get to $3005$. What I thought to do: calculate the number of total functions I can do with $A \times A$, which is $3125$. Find out the number of surjective functions and just remove them. I mean: nonsurjective functions = Total functions minus surjective functions.
But the question is, how do I find the total of surjective functions?

Edit: Please use basic tools, as I haven't learnt lot of formulas and such… I saw on other topics stuff I could have never dreamt of seeing…

Best Answer

Let's summarize the discussion in the comments.

Let $A = \{1, 2, 3, 4, 5\}$. Your strategy of finding the number of functions $f: A \to A$ which are not surjective by subtracting the number of surjective functions from the number of functions $f: A \to A$ is correct.

A function assigns to each element of the domain an image in the codomain. Since there are five possible images in the codomain for each of the five elements in the domain, there are $5^5$ functions $f: A \to A$.

Since the domain and codomain are the same, a function $f: A \to A$ can only be surjective if it is also injective since not every element in the codomain will be the image of an element in the domain unless each element in the domain is assigned a different image. If $f: A \to A$ is injective, then there are five ways to assign $f(1)$, which leaves four ways to assign $f(2)$, three ways to assign $f(3)$, two ways to assign $f(4)$, and one way to assign $f(5)$. Hence, there are $5! = 5 \cdot 4 \cdot 3 \cdot 2 \cdot 1$ injective functions $f: A \to A$. Since the injective functions $f: A \to A$ are also the surjective functions $f: A \to A$, there are $5!$ surjective functions $f: A \to A$.

Thus, the number of functions $f: A \to A$ which are not surjective is $5^5 - 5! = 3125 - 120 = 3005$.