Solving a bijective function task How would you solve this task actually? This is not homework btw, i'm just trying to understand how you can solve tasks like this.

Let $S$ be the set $\{$$1,2,3,4,5$$\}$. How many functions from $S$ to $S$ are there and how many of these are bijective?

Thanks alot for any help. 
 A: Every function from $S$ to $S$ can be considered as a set like this $f=\{(1,a_1),(2,a_2),(3,a_3),(4,a_4),(5,a_5)\}$. Now the rest of the question specifies the conditions for $a_i$s. For example for the bijective case all $a_i$s should be different so the number of ways that we can set them is $5!$.
A: Suppose that you want to build a function $f$ from a set $A$ of $m$ elements to a set $B$ of $n$ elements. You can list $A$ as $A=\{a_1,a_2,\ldots,a_m\}$. Now go down the line choosing values of $f(a_1)$, $f(a_2)$, and so on. If there is no restriction on your function, there are $n$ possible choices for $f(a_1)$: it can be any element of $B$. There are still $n$ choices for $f(a_2)$, since we imposed no restriction on $f$, and $n$ choices for $f(a_3)$, and so on: for $k=1,\ldots,m$ there are $n$ choices for $f(a_k)$. These choices can be made independently, so by the multiplication principle there are $$\underbrace{n\cdot n\cdot\ldots\cdot n}_{m\text{ copies}}=n^m$$ functions from $A$ to $B$. In your case that’s $5^5=3125$ functions.
If $m\le n$, we can talk about injections. There are now $n$ possible choices for $f(a_1)$, since it can be any of the $m$ elements of $B$. For $f(a_2)$, however, there are now only $n-1$ possible choices: if we want a bijection, we can’t re-use $f(a_1)$. Similar reasoning shows that there must be
$$\underbrace{n(n-1)(n-2)\ldots(n-m+1)}_{m\text{ factors}}=\frac{n!}{(n-m)!}$$
injections from $A$ to $B$. In your case $m=n=5$, so the injections are precisely the bijections, and their number is $\frac{5!}{0!}=5!=120$.
