If a function $f$ is defined as $f : \{1, 2, 3, 4\}\to \{1, 2, 3, 4\}$ such that $$f(f(x)) = f(x), \ \ \ \ \forall x\in \{1, 2, 3, 4\}.$$ and $S$ is the number of such functions then find $S$.
We can easily figure out that one way of doing this is $f(x) =x$. Then $$f(f(x)) = f(x) = x.$$ Or we can have some cases like $f(i) = i$ only for some elements and others are mapped carefully according to the conditions.
How should I proceed? Also can you suggest some alternate methods.
$\newcommand{\ran}{\operatorname{ran}}$I’ll get you started. The requirement that $f\big(f(x)\big)=f(x)$ means that every element of the range of $f$ must be a fixed point of $f$, i.e., a point such that $f(x)=x$.