TITLE: Let $g_{n}$ be the no. of derangements with $n$ elements and $f_{n}$ the no. of permutations with one fixed point. Show that $|g_{n}-f_{n}|=1$
QUESTION [5 upvotes]: This is a problem from Loren Larson's "Problem solving through problems", 2.5.13, page 78.
Let $S_{n}=${$1,2,...,n$}. A derangement of $S_{n}$ is a permutation with no fixed points. Let $g_{n}$ be the number of derangements, and $f_{n}$ the number of permutations of $S_{n}$ with exactly one fixed point. Show that $|f_{n}-g_{n}|=1$
I proved that $g_{n}=(n-1)(g_{n-1}+g_{n-2})$, and by analyzing the number of permutations for $S_{3}$ and $S_{4}$ I've conjectured that $g_{2n}=f_{2n}+1$, and $g_{2n+1}=f_{2n+1}-1$, although I don't know how to prove it. I also found that $f_{n+1}=(n+1)g_{n}$.

REPLY [3 votes]: Let $D_n$ be the number of derangements in $S_n$. Obviously the number of permutations with exactly one fixed point is given by $n D_{n-1}$, so we just have to prove that for every $n$,
$$ A_n = D_n-nD_{n-1}\in\{-1,1\}.$$
Let $\sigma$ be a derangement in $S_n$ and let $m=\sigma^{-1}(n)$. If we consider:
$$ \tau = \sigma\, (n m) $$
i.e. the permutation we get by swapping the images of $n$ and $m$, we obviously have $\tau(n)=n$. Then, there are two cases: if $\tau(m)=m$, $\tau$ has exactly two fixed points, otherwise $n$ is the only fixed point. That leads (see also this question) to:
$$ D_n = (n-1)\left(D_{n-1}+D_{n-2}\right) $$
that can be written as $A_n = -A_{n-1}$. Since $A_2=1$, the claim follows by induction.