2. (15 points) Given $p, q(q \neq 0)$ are real numbers, the equation $x^{2}-p x+q=0$ has two real roots $\alpha, \beta$, and the sequence $\left\{a_{n}\right\}$ satisfies $a_{1}=p, a_{2}=p^{2}-q, a_{n}=p a_{n-1}-q a_{n-2}(n=$ $3,4, \cdots)$.
(1) Find the general term formula of the sequence $\left\{a_{n}\right\}$ (expressed in terms of $\alpha, \beta$);
(2) If $p=1, q=\frac{1}{4}$, find the sum of the first $n$ terms of $\left\{a_{n}\right\}$.
2. Solution 1: (1) By Vieta's formulas, we know $\alpha \beta=q \neq 0$. Also, since $\alpha+\beta=p$, we have
$$
a_{n}=p a_{n-1}-q a_{n-2}
$$
$$
=(\alpha+\beta) a_{n-1}-\alpha \beta a_{n-2}(n=3,4, \cdots) \text {. }
$$

Rearranging gives $a_{n}-\beta a_{n-1}=\alpha\left(a_{n-1}-\beta a_{n-2}\right)$.
Let $b_{n}=a_{n+1}-\beta a_{n}$. Then
$$
b_{n+1}=\alpha b_{n}(n=1,2, \cdots) \text {. }
$$

Thus, $\left\{b_{n}\right\}$ is a geometric sequence with common ratio $\alpha$.
The first term of the sequence $\left\{b_{n}\right\}$ is
$$
\begin{array}{l}
b_{1}=a_{2}-\beta a_{1}=p^{2}-q-\beta p \\
=(\alpha+\beta)^{2}-\alpha \beta-\beta(\alpha+\beta)=\alpha^{2} .
\end{array}
$$

Therefore, $b_{n}=\alpha^{2} \cdot \alpha^{n-1}=\alpha^{n+1}$, i.e.,
$$
a_{n+1}-\beta a_{n}=\alpha^{n+1}(n=1,2, \cdots) \text {. }
$$

Thus, $a_{n+1}=\beta a_{n}+\alpha^{n+1}(n=1,2, \cdots)$.
$$
\begin{array}{l}
\text { (i) When } \Delta=p^{2}-4 q=0 \text {, } \alpha=\beta \neq 0 . \\
a_{1}=p=\alpha+\alpha=2 \alpha, \\
a_{n+1}=\beta a_{n}+\alpha^{n+1} \\
\Rightarrow a_{n+1}=\alpha a_{n}+\alpha^{n+1} \\
\Rightarrow \frac{a_{n+1}}{\alpha^{n+1}}-\frac{a_{n}}{\alpha^{n}}=1 \quad(n=1,2, \cdots) .
\end{array}
$$

Thus, the sequence $\left\{\frac{a_{n}}{\alpha^{n}}\right\}$ is an arithmetic sequence with common difference 1, and its first term is $\frac{a_{1}}{\alpha}=\frac{2 \alpha}{\alpha}=2$. Therefore,
$$
\frac{a_{n}}{\alpha^{n}}=2+1 \times(n-1)=n+1 \text {. }
$$

Thus, the general term formula of the sequence $\left\{a_{n}\right\}$ is
$$
a_{n}=(n+1) \alpha^{n} \text {. }
$$
(ii) When $\Delta=p^{2}-4 q>0$, $\alpha \neq \beta$.
Similarly, we get
$$
a_{n+1}-\alpha a_{n}=\beta^{n+1}(n=1,2, \cdots) \text {. }
$$

Combining equations (1) and (2), the general term formula of the sequence $\left\{a_{n}\right\}$ is
$$
a_{n}=\frac{\beta^{n+1}-\alpha^{n+1}}{\beta-\alpha} .
$$
(2) If $p=1, q=\frac{1}{4}$, then $\Delta=p^{2}-4 q=0$. In this case, $\alpha=\beta=\frac{1}{2}$.
By the result of (1), the general term formula of the sequence $\left\{a_{n}\right\}$ is
$$
a_{n}=(n+1)\left(\frac{1}{2}\right)^{n}=\frac{n+1}{2^{n}} \text {. }
$$

Thus, the sum of the first $n$ terms of $\left\{a_{n}\right\}$ is
$S_{n}=\frac{2}{2}+\frac{3}{2^{2}}+\frac{4}{2^{3}}+\cdots+\frac{n}{2^{n-1}}+\frac{n+1}{2^{n}}$,
$$
\frac{1}{2} S_{n}=\frac{2}{2^{2}}+\frac{3}{2^{3}}+\frac{4}{2^{4}}+\cdots+\frac{n}{2^{n}}+\frac{n+1}{2^{n+1}} \text {. }
$$

Subtracting and rearranging the above two equations, we get
$$
\frac{1}{2} S_{n}=\frac{3}{2}-\frac{n+3}{2^{n+1}} \text {. }
$$

Thus, $S_{n}=3-\frac{n+3}{2^{n}}$.
Solution 2: (1) By Vieta's formulas, we know $\alpha \beta=q \neq 0$.
Also, since $\alpha+\beta=p$, we have
$$
a_{1}=\alpha+\beta, a_{2}=\alpha^{2}+\beta^{2}+\alpha \beta \text {. }
$$

The roots of the characteristic equation $\lambda^{2}-p \lambda+q=0$ are $\alpha, \beta$.
(i) When $\alpha=\beta \neq 0$, the general term is
$$
a_{n}=\left(A_{1}+A_{2} n\right) \alpha^{n}(n=1,2, \cdots) \text {. }
$$

From $a_{1}=2 \alpha, a_{2}=3 \alpha^{2}$, we get
$$
\left\{\begin{array}{l}
\left(A_{1}+A_{2}\right) \alpha=2 \alpha, \\
\left(A_{1}+2 A_{2}\right) \alpha^{2}=3 \alpha^{2} .
\end{array}\right.
$$

Solving gives $A_{1}=A_{2}=1$. Thus, $a_{n}=(1+n) \alpha^{n}$.
(ii) When $\alpha \neq \beta$, the general term is
$$
a_{n}=A_{1} \alpha^{n}+A_{2} \beta^{n}(n=1,2, \cdots) \text {. }
$$

From $a_{1}=\alpha+\beta, a_{2}=\alpha^{2}+\beta^{2}+\alpha \beta$, we get
$$
\left\{\begin{array}{l}
A_{1} \alpha+A_{2} \beta=\alpha+\beta, \\
A_{1} \alpha^{2}+A_{2} \beta^{2}=\alpha^{2}+\beta^{2}+\alpha \beta
\end{array}\right.
$$

Solving gives $A_{1}=\frac{-\alpha}{\beta-\alpha}, A_{2}=\frac{\beta}{\beta-\alpha}$.
Thus, $a_{n}=\frac{-\alpha^{n+1}}{\beta-\alpha}+\frac{\beta^{n+1}}{\beta-\alpha}=\frac{\beta^{n+1}-\alpha^{n+1}}{\beta-\alpha}$.
(2) Same as Solution 1.