we say that a function like $f:X \to X$ has root if exists a function like $g:X\to X$ that for every $x \in X$: $$f(x) = g(g(x))$$
what is a necessary and sufficient condition for $f$ that it has a root.
for example the below function hasn't any root:
$$f:\mathbb{Z}_4 \to \mathbb{Z}_4$$ $$f(x) = x+1$$