Example 2.5 Let $g_{n}$ denote the number of different permutations of $2 n(n \geqslant 2)$ distinct elements $a_{1}, a_{2}, \cdots, a_{n}, b_{1}$, $b_{2}, \cdots, b_{n}$ such that $a_{k}$ and $b_{k}(k=1,2, \cdots, n)$ are not adjacent. Find the counting formula for $g_{n}$.
Let $S$ denote the set of all permutations formed by $2n (n \geqslant 2)$ distinct elements $a_{1}, a_{2}, \cdots, a_{n}, b_{1}, b_{2}, \cdots, b_{n}$, then $|S|=(2 n)$. Let $A_{i}(i=1,2, \cdots, n)$ denote the set of permutations in $S$ where $a_{i}$ and $b_{i}$ are adjacent, then
$$
\begin{aligned}
g_{n} & =\left|S-\bigcup_{i=1}^{n} A_{i}\right| \\
& =|S|+\sum_{k=1}^{n}(-1)^{k} \sum_{1 \leqslant i_{1}<i_{2}<\cdots<i_{k} \leqslant n}\left|A_{i_{1}} \cap A_{i_{2}} \cap \cdots \cap A_{i_{k}}\right| .
\end{aligned}
$$

Since $A_{i_{1}} \cap A_{i_{2}} \cap \cdots \cap A_{i_{k}}\left(1 \leqslant i_{1}<i_{2}<\cdots<i_{k} \leqslant n\right)$ represents the set of all permutations formed by $a_{1}, a_{2}, \cdots, a_{n}, b_{1}, b_{2}, \cdots, b_{n}$ where $a_{i_{j}}$ and $b_{i_{j}}(j=1,2, \cdots, k)$ are adjacent, we have
$$
\left|A_{i_{1}} \cap A_{i_{2}} \cap \cdots \cap A_{i_{k}}\right|=2^{k} \cdot(2 n-k)!,
$$

Thus,
$$
\begin{aligned}
g_{n} & =(2 n)!+\sum_{k=1}^{n}(-1)^{k}\binom{n}{k} 2^{k}(2 n-k)! \\
& =\sum_{k=0}^{n}(-1)^{k}\binom{n}{k} 2^{k} \cdot(2 n-k)!
\end{aligned}
$$