Let $A = \{0,1,2\}$. Determine all total functions $f:A \rightarrow A$ for which $f^2(x) = f(x)$, where $f^2 = f \circ f$ and find how many such total functions are there?
My thoughts: I know what is total function (it is just function defined all domain), but could not understand how to construct these functions.
Suppose $f(x)=y$. Then $f^2(x)=f(x)\Rightarrow f(y)=y$. In other words $f$ must map any element in the image of $f$ to itself.
We now have three cases: the image of $f$ can contain one element, two elements or be the whole of $A$.
There are $3$ functions where the image of $f$ contains one element. Each such $f$ certainly maps the single element in its image to itself.
There are $18$ functions where the image of $f$ contains two elements. But in only $6$ of these is each element in the image of $f$ mapped to itself.
There are $6$ functions where the image of $f$ is the whole of $A$. But there is only one such function that maps each element of $A$ to itself.
So the answer is $3+6+1=10$.
It will be instructive if you write out explicitly each of these $10$ functions.