2. Given a positive integer $n \geq 2, x_{1}, x_{2}, \ldots, x_{n}$ are non-negative real numbers satisfying $\sum_{i=1}^{n} x_{i}^{2}=1, M=\max \left\{x_{1}, x_{2}, \ldots, x_{n}\right\}$, and set $S=n M^{2}+2 \sum_{i<j} x_{i} x_{j}$. Try to find the maximum and minimum values of $S$.
$$
\sqrt{n}+n-1
$$

Let $t=\left\{\begin{array}{cc}[\sqrt{n}], & \{\sqrt{n}\}<\frac{1}{2} \\ [\sqrt{n}]+1, & \{\sqrt{n}\} \geq \frac{1}{2}\end{array}\right.$, then when $x_{1}=x_{2}=\mathrm{L}=x_{t}=\frac{1}{\sqrt{t}}, x_{t+1}=\mathrm{L}=x_{n}=0$,
$$
S=\frac{n}{t}+t-1
$$

Below, we prove: $S \geq \frac{n}{t}+t-1$. It is sufficient to prove: $n x_{1}^{2}+\left(\sum_{i=1}^{n} x_{i}\right)^{2}-\left(t+\frac{n}{t}\right) \sum_{i=1}^{n} x_{i}^{2} \geq 0 \quad\left({ }^{*}\right)_{0}$. Now, we prove this without the condition $\sum_{i=1}^{n} x_{i}^{2}=1$.

Consider the left side of (*) as a quadratic function of $x_{2}$. Since the coefficient of the quadratic term is less than 0, the minimum value is reached when $x_{2}=x_{1}$ or 0. Similarly, when $x_{3}, x_{4}, \mathrm{~L}, x_{n}$ are all $x_{1}$ or 0, the left side of (*) reaches its minimum value.
Assume $x_{2}, x_{3}, \mathrm{~L}, x_{n}$ have $s-1$ values of $x_{1}$, and the remaining $n-s$ values are 0, then
$$
n x_{1}^{2}+\left(\sum_{i=1}^{n} x_{i}\right)^{2}-\left(t+\frac{n}{t}\right) \sum_{i=1}^{n} x_{i}^{2}=n x_{1}^{2}+s^{2} x_{1}^{2}-\left(t+\frac{n}{t}\right) s x_{1}^{2}=s x_{1}^{2}\left(s+\frac{n}{s}-\left(t+\frac{n}{t}\right)\right),
$$

Since the minimum value of $s+\frac{n}{s}$ is $t+\frac{n}{t}$, (*) holds, i.e., the minimum value is $\frac{n}{t}+t-1$.
2. Solution: Assume $M=x_{1}$, then $S=n x_{1}^{2}+\left(\sum_{i=1}^{n} x_{i}\right)^{2}-\sum_{i=1}^{n} x_{i}^{2}=n x_{1}^{2}+\left(\sum_{i=1}^{n} x_{i}\right)^{2}-1$.

By the Cauchy-Schwarz inequality, we have:
$$
\begin{aligned}
\left(\sum_{i=1}^{n} x_{i}\right)^{2} & \leq\left(1+\frac{1}{\sqrt{n}+1}+\mathrm{L}+\frac{1}{\sqrt{n}+1}\right)\left(x_{1}^{2}+(\sqrt{n}+1) x_{2}^{2}+\mathrm{L}+(\sqrt{n}+1) x_{n}^{2}\right) \\
& =\sqrt{n} x_{1}^{2}+(\sqrt{n}+n) x_{2}^{2}+\mathrm{L}+(\sqrt{n}+n) x_{n}^{2}
\end{aligned}
$$

Thus, $S \leq(\sqrt{n}+n) x_{1}^{2}+(\sqrt{n}+n) x_{2}^{2}+\mathrm{L}+(\sqrt{n}+n) x_{n}^{2}-1=\sqrt{n}+n-1$.
When $x_{2}=x_{3}=\mathrm{L}=x_{n}$ and $x_{1}=(\sqrt{n}+1) x_{2}$, the equality holds, i.e., the maximum value of the original expression is $\sqrt{n}+n-1$.