Example 6: Person A and Person B independently toss a fair coin $n$ times each. Find the probability that the number of heads is the same.

 untranslated part:
甲、乙两人分别独立地投掷 $n$ 次质地均匀的硬币. 求正面次数相同的概率. 

The translated part:
Person A and Person B independently toss a fair coin $n$ times each. Find the probability that the number of heads is the same.
【Analysis】Let
Event $A_{k}$: A tosses a fair coin $n$ times, with $k$ heads up;

Event $B_{k}$: B tosses a fair coin $n$ times, with $k$ heads up;

Event $C_{k}$: A and B each toss a fair coin $n$ times, both with $k$ heads up.
Then $P\left(A_{k}\right)=P\left(B_{k}\right)=\mathrm{C}_{n}^{k}\left(\frac{1}{2}\right)^{n}$,
$P\left(C_{k}\right)=P\left(A_{k}\right) P\left(B_{k}\right)=\left(\frac{\mathrm{C}_{n}^{k}}{2^{n}}\right)^{2}$.
Therefore, the required probability is
$p=\sum_{k=0}^{n}\left(\frac{\mathrm{C}_{n}^{k}}{2^{n}}\right)^{2}=\sum_{k=0}^{n} \frac{\left(\mathrm{C}_{n}^{k}\right)^{2}}{4^{n}}=\frac{\sum_{k=0}^{n}\left(\mathrm{C}_{n}^{k}\right)^{2}}{4^{n}}$.
Next, we calculate $\sum_{k=0}^{n}\left(\mathrm{C}_{n}^{k}\right)^{2}$.
Let the generating function $\varphi(x)=(1+x)^{n}\left(1+\frac{1}{x}\right)^{n}$.
Notice that, the general term of the expansion of $(1+x)^{n}$ is $\mathrm{C}_{n}^{k} x^{k}$, and the general term of the expansion of $\left(1+\frac{1}{x}\right)^{n}$ is $\mathrm{C}_{n}^{r} x^{-r}$.

Thus, $\sum_{k=0}^{n}\left(\mathrm{C}_{n}^{k}\right)^{2}$ corresponds to the constant term in the expansion of the generating function.
On the other hand,
$$
(1+x)^{n}\left(1+\frac{1}{x}\right)^{n}=\frac{(1+x)^{2 n}}{x^{n}},
$$

To find the constant term in its expansion, we only need to find the coefficient of the $x^{n}$ term in $(1+x)^{2 n}$, which is $\mathrm{C}_{2 n}^{n}$.
Therefore, $\sum_{k=0}^{n}\left(\mathrm{C}_{n}^{k}\right)^{2}=\mathrm{C}_{2 n}^{n}$.
Hence, the required probability is
$$
\begin{aligned}
p & =\frac{\mathrm{C}_{2 n}^{n}}{4^{n}}=\frac{(2 n)!}{(n!)(n!) 4^{n}} \\
& =\frac{(2 n-1)!}{(n!)((n-1)!) 2^{2 n-1}} .
\end{aligned}
$$