TITLE: Number of functions $f : A \to A$ with $f(f(x)) = x$
QUESTION [7 upvotes]: Let $A$ be set such that $n(A)=5$. How many functions can we define on $A$ with the property $(f\circ f)(x)=x$ ?
I think the identity function works but what about others? Should $f$ have an inverse?  I think permutations may be involved, but I am not sure how to progress.

REPLY [3 votes]: This can be solved using recursion. Let $u_n$ be the number of involutions of $\{1,\dotsc,n\}$.
To make things concrete, we'll consider $u_5$. We'll proceed by asking what $5$ is mapped to. Either to $5$ or to something else. If it's mapped to $5$ then there are $u_4$ further continuations. If on the other hand $5$ gets mapped to some other $k$, you can remove $5$ and $k$ from the set, and relabel the remaining elements $\{1,\dotsc,3\}$.
Ergo, we have that $u_5 = u_4 + 4\times u_3$.
In general we get the following recurrence relation: $$u_n = u_{n-1} + (n-1)u_{n-2}\\u_1 = 1 \\u_2 = 2$$. This recurrence defines the telephone numbers. The answer to your question is thus $u_5 = 26$.