If for $f: \mathbb{R} \rightarrow \mathbb{R}$ $f(f(x))=x \quad \forall x \in \mathbb{R}$, can we say that the function is surjective?
I came across this problem while solving a different problem, and I think the answer should be yes, because all such real $x$ is getting mapped to by the function. So it should be surjective, however I'm not sure as I'm quite new in learning functions, so I want to verify my answer. Thank you.
Yes, we can, for the reason you mention.
By definition, $f$ is surjective iff:
Since for any given $x$, you can take $y:=f(x)$ and have $f(y)=f(f(x))=x$, $f$ is surjective.
Such $f$ are called involutions.
There is absolutely nothing special about $\Bbb R$ here. If $X$ is any set, $f:X\to X$ any involution (that is, $f(f(x))=x$ for all $x\in X$) then it follows $f$ is surjective.