概率论与数理统计 (Spring 2023)/Average-case analysis of QuickSort: Difference between revisions

From TCS Wiki
Jump to navigation Jump to search
No edit summary
Line 91: Line 91:
因此总比较次数<math>X</math>可被计算如下:
因此总比较次数<math>X</math>可被计算如下:
:<math>X=\sum_{i<j}I_{ij}</math>.
:<math>X=\sum_{i<j}I_{ij}</math>.
根据期望的线性:
:<math>\mathbb{E}[X]=\sum_{i<j}\mathbb{E}[I_{ij}]=\sum_{i<j}\Pr(A_{ij})</math>.


因此接下来,仅需要针对每一对具体的<math>1\le i<j\le n</math>,计算概率:
:<math>\Pr(A_{ij})=\Pr(a_i\text{和}a_j\text{在算法中进行了比较})</math>.


定下任意一对具体的<math>1\le i<j\le n</math>。
在算法运行之初(顶层递归调用),元素<math>a_i</math>与<math>a_j</math>显然有<math>a_i<a_j</math>、且同属于当前递归调用的输入数组<math>A</math>。
此时根据'''pivot'''的选取,有如下三种可能的情况:
# '''pivot'''刚好选中<math>a_i</math>或<math>a_j</math>之一,此时<math>a_i</math>与<math>a_j</math>之间必被比较(因为'''pivot'''会与当前数组内的所有元素进行比较),因此事件<math>A_{ij}</math>确定发生;
# <math>a_i<</math>'''pivot'''<math><a_j</math>,即'''pivot'''取值在<math>a_i</math>与<math>a_j</math>之间,此时<math>a_i</math>与<math>a_j</math>会被大小居于其中间的'''pivot'''元素分别分流到子数组<math>L</math>与<math>R</math>中,且在之后的递归调用中永不再见,因此不会被比较,事件<math>A_{ij}</math>确定不发生;
# '''pivot'''选中了比<math>a_i</math>更小或者比<math>a_j</math>更大的元素,在此情况下<math>a_i</math>与<math>a_j</math>,连同它们之间的所有元素<math>\{a_k\mid i<k<j\}</math>,都会被分到同一个子数组<math>L</math>或者<math>R</math>中,而此时<math>A_{ij}</math>的发生与否尚未确定,需要递归至下一层(而且输入是<math>a_i</math>与<math>a_j</math>所同属的那个子数组)再确定。
不难看出,上述三种情况的分析,对于任意<math>A_{ij}</math>发生与否尚未确定的当前递归调用(即<math>a_i</math>与<math>a_j</math>同属于当前递归调用的输入数组),都仍然是成立的。
从而,上述情况分类可不断递归进行下去,直至事件<math>A_{ij}</math>的发生与否被完全确定下来。


Our goal is to analyze the expected number of comparisons during an execution of RandQSort with an arbitrary input <math>S</math>. We achieve this by measuring the chance that each pair of elements are compared, and summing all of them up due to [http://en.wikipedia.org/wiki/Expected_value#Linearity Linearity of Expectation].
因此,可以得出:<math>A_{ij}</math>发生,当且仅当在上述情况(1)或(2)之一发生的前提下有(1)发生。
 
除此之外,如下两个观察通过递归验证易得:
Let <math>a_i</math> denote the <math>i</math>th smallest element in <math>S</math>.
* 当<math>a_i</math><math>a_j</math>同属于当前递归调用的输入数组时,它们之间的所有元素<math>\{a_k\mid i<k<j\}</math>也属于该数组;
Let <math>X_{ij}\in\{0,1\}</math> be the random variable which indicates whether <math>a_i</math> and <math>a_j</math> are compared during the execution of RandQSort. That is:
* 在任何递归调用中,'''pivot'''始终在当前输入数组中均匀分布。
 
综上可得:
:<math>
:<math>\Pr(A_{ij})=\Pr(\mathsf{pivot}\in\{a_i,a_j\}\mid\mathsf{pivot}\in\{a_i,a_{i+1},\ldots,a_{j}\})=\frac{2}{j-i+1}</math>.
\begin{align}
X_{ij} &=
\begin{cases}
1 & a_i\mbox{ and }a_j\mbox{ are compared}\\
0 & \mbox{otherwise}
\end{cases}.
\end{align}
</math>
 
Elements <math>a_i</math> and <math>a_j</math> are compared only if one of them is chosen as pivot. After comparison they are separated (thus are never compared again). So we have the following observation:
 
'''Claim 1:  Every pair of <math>a_i</math> and <math>a_j</math> are compared at most once.'''
 
Therefore the sum of <math>X_{ij}</math> for all pair <math>\{i, j\}</math> gives the total number of comparisons. The expected number of comparisons is <math>\mathbf{E}\left[\sum_{i=1}^n\sum_{j>i}X_{ij}\right]</math>. Due to [http://en.wikipedia.org/wiki/Expected_value#Linearity Linearity of Expectation], <math>\mathbf{E}\left[\sum_{i=1}^n\sum_{j>i}X_{ij}\right] = \sum_{i=1}^n\sum_{j>i}\mathbf{E}\left[X_{ij}\right]</math>.
Our next step is to analyze <math>\mathbf{E}\left[X_{ij}\right]</math> for each <math>\{i, j\}</math>.
 
By the definition of expectation and <math>X_{ij}</math>,


算法总比较次数的期望<math>\mathbb{E}[X]</math>可被计算如下:
:<math>\begin{align}
:<math>\begin{align}
\mathbf{E}\left[X_{ij}\right]
\mathbb{E}\left[X\right]  
&= 1\cdot \Pr[a_i\mbox{ and }a_j\mbox{ are compared}] + 0\cdot \Pr[a_i\mbox{ and }a_j\mbox{ are not compared}]\\
&= \Pr[a_i\mbox{ and }a_j\mbox{ are compared}].
\end{align}</math>
 
We are going to bound this probability.
 
'''Claim 2: <math>a_i</math> and <math>a_j</math> are compared if and only if one of them is chosen as pivot when they are still in the same subset.'''
 
This is easy to verify: just check the algorithm. The next one is a bit complicated.
 
'''Claim 3: If <math>a_i</math> and <math>a_j</math> are still in the same subset then all <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math> are in the same subset.'''
 
We can verify this by induction. Initially, <math>S</math> itself has the property described above; and partitioning any <math>S</math> with the property into <math>S_1</math> and <math>S_2</math> will preserve the property for both <math>S_1</math> and <math>S_2</math>. Therefore Claim 3 holds.
 
Combining Claim 2 and 3, we have:
 
'''Claim 4: <math>a_i</math> and <math>a_j</math> are compared only if one of <math>\{a_i, a_j\}</math> is chosen from <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math>.'''
 
And apparently,
 
'''Claim 5: Every one of <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math> is chosen equal-probably.'''
 
This is because our RandQSort chooses the pivot ''uniformly at random''.
 
Claim 4 and Claim 5 together imply:
 
:<math>\begin{align}
\Pr[a_i\mbox{ and }a_j\mbox{ are compared}]
&\le \frac{2}{j-i+1}.
\end{align}</math>
 
{|border="1"
|'''Remark:''' Perhaps you feel confused about the above argument. You may ask: "''The algorithm chooses pivots for many times during the execution. Why in the above argument, it looks like the pivot is chosen only once?''" Good question! Let's see what really happens by looking closely.
 
For any pair <math>a_i</math> and <math>a_j</math>, initially <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math> are all in the same set <math>S</math> (obviously!). During the execution of the algorithm, the set which containing <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math> are shrinking (due to the pivoting), until one of <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math> is chosen, and the set is partitioned into different subsets. We ask for the probability that the chosen one is among <math>\{a_i, a_j\}</math>. So we really care about "the last" pivoting before <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math> is split.
 
Formally, let <math>Y</math> be the random variable denoting the pivot element. We know that for each <math>a_k\in\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math>, <math>Y=a_k</math> with the same probability, and <math>Y\not\in\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math> with an unknown probability (remember that there might be other elements in the same subset with <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math>). The probability we are looking for is actually
<math>\Pr[Y\in \{a_i, a_j\}\mid Y\in\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}]</math>, which is always <math>\frac{2}{j-i+1}</math>, provided that <math>Y</math> is uniform over <math>\{a_i, a_{i+1}, \ldots, a_{j-1}, a_{j}\}</math>.
 
The '''conditional probability''' rules out the ''irrelevant'' events in a probabilistic argument.
|}
 
Summing all up:
 
:<math>\begin{align}
\mathbf{E}\left[\sum_{i=1}^n\sum_{j>i}X_{ij}\right]  
&=  
&=  
\sum_{i=1}^n\sum_{j>i}\mathbf{E}\left[X_{ij}\right]\\
\sum_{i<j}\Pr(A_{ij})\\
&\le \sum_{i=1}^n\sum_{j>i}\frac{2}{j-i+1}\\
&\le \sum_{i=1}^n\sum_{j=i}^n\frac{2}{j-i+1}\\
&= \sum_{i=1}^n\sum_{k=2}^{n-i+1}\frac{2}{k} & & (\mbox{Let }k=j-i+1)\\
&= \sum_{i=1}^n\sum_{k=2}^{n-i+1}\frac{2}{k} & & (\mbox{Let }k=j-i+1)\\
&\le \sum_{i=1}^n\sum_{k=1}^{n}\frac{2}{k}\\
&\le \sum_{i=1}^n\sum_{k=1}^{n}\frac{2}{k}\\
Line 174: Line 124:
&= 2n H(n).
&= 2n H(n).
\end{align}</math>
\end{align}</math>
 
此处<math>H(n)=\sum_{k=1}^{n}\frac{1}{k}</math>是第<math>n</math>[http://en.wikipedia.org/wiki/Harmonic_number 调和数]
<math>H(n)</math> is the <math>n</math>th [http://en.wikipedia.org/wiki/Harmonic_number Harmonic number]. It holds that
 
:<math>\begin{align}H(n) = \ln n+O(1)\end{align}</math>.
 
Therefore, for an arbitrary input <math>S</math> of <math>n</math> numbers, the expected number of comparisons taken by RandQSort to sort <math>S</math> is <math>\mathrm{O}(n\log n)</math>.

Revision as of 14:19, 12 April 2023

快速排序Quicksort是由Tony Hoare发现的基于比较的(comparison-based)排序算法。该算法的伪代码描述如下(为方便起见,假设数组元素互不相同——更一般情况的分析易推广得到):

 QSort(A): 输入A[1...n]是存有n个不同数字的数组
 if n>1 then
      pivot = A[1];
      将A中<pivot的元素存于数组L,将A中>pivot的元素存于数组R; \\保持内部元素之间相对顺序
      递归调用QSort(L)和QSort(R);

该伪代码描述省略了对数组的存取归并等具体实现的交代。可以不妨认为算法中的[math]\displaystyle{ L }[/math][math]\displaystyle{ R }[/math]其实就分别是原数组[math]\displaystyle{ A }[/math]的前半部分[math]\displaystyle{ A[1...i-1] }[/math]和后半部分[math]\displaystyle{ A[i...n] }[/math],其中[math]\displaystyle{ i }[/math]表示pivot(“基准”、“轴点”、“分水岭”元素)在数组[math]\displaystyle{ A }[/math]中的序数,即pivot是数组[math]\displaystyle{ A }[/math]中第[math]\displaystyle{ i }[/math]小的数。

作为基于比较的排序算法,我们将算法进行的元素间的比较次数作为算法的复杂性度量。在最坏情况worst-case)输入下,我们描述的“快速排序”算法所使用的比较次数可以达到[math]\displaystyle{ \Theta(n^2) }[/math]。而且有趣的是,这一[math]\displaystyle{ \Omega(n^2) }[/math]的复杂度下界是在输入数组是一个已排好序的数组时达到的:此时pivot会将数组[math]\displaystyle{ A }[/math]划分为大小极不平衡的子数组[math]\displaystyle{ L }[/math][math]\displaystyle{ R }[/math],递归树也因此极不平衡,而算法使用的比较次数可因此达到[math]\displaystyle{ (n-1)+(n-2)+(n-3)+\cdots+1=\Omega(n^2) }[/math]

现在我们来分析这一算法的平均情况average-case)复杂度。

快速排序算法的平均复杂度分析 I(基于全期望法则)

令输入数组[math]\displaystyle{ A }[/math][math]\displaystyle{ n }[/math]个元素的均匀分布的随机排列。不难验证:上述快速排序算法使用的比较次数,仅与[math]\displaystyle{ A }[/math]中元素的相对大小有关、而与具体数值无关。因此,不妨假设[math]\displaystyle{ A }[/math][math]\displaystyle{ n }[/math]次对称群[math]\displaystyle{ \mathcal{S}_n }[/math]中均匀分布的随机[math]\displaystyle{ n }[/math]元排列。

令随机变量[math]\displaystyle{ X_n }[/math]表示在该随机输入[math]\displaystyle{ A }[/math]下,快速排序算法使用的总比较次数。同时令[math]\displaystyle{ t(n)=\mathbb{E}[X_n] }[/math]表示其期望。正如刚刚解释的,[math]\displaystyle{ t(n) }[/math]是良定义的,因为期望值[math]\displaystyle{ \mathbb{E}[X_n] }[/math]仅与[math]\displaystyle{ n }[/math]有关。

[math]\displaystyle{ 1\le i\le n }[/math],定义[math]\displaystyle{ B_i }[/math]为如下事件:

  • pivot在数组[math]\displaystyle{ A }[/math]中是第[math]\displaystyle{ i }[/math]小的元素。

[math]\displaystyle{ B_1,B_2,\ldots,B_n }[/math]构成了对所有情况(样本空间)的一个划分。且每个事件[math]\displaystyle{ B_i }[/math]发生的概率有:

[math]\displaystyle{ \Pr(B_i)=\frac{(n-1)!}{n!}=\frac{1}{n} }[/math].

这是因为事件[math]\displaystyle{ B_i }[/math]等价于一个均匀分布的随机排列[math]\displaystyle{ \pi:[n]\xrightarrow[\text{onto}]{\text{1-1}}[n] }[/math][math]\displaystyle{ \pi(1)=i }[/math],而这件事的概率为[math]\displaystyle{ \frac{1}{n} }[/math]

因此,根据全期望法则law of total expectation),有:

[math]\displaystyle{ \begin{align} t(n) = \mathbb{E}[X_n] &= \sum_{i=1}^n\mathbb{E}[X_n\mid B_i]\Pr(B_i) = \frac{1}{n}\sum_{i=1}^n\mathbb{E}[X_n\mid B_i] \end{align} }[/math].

而当事件[math]\displaystyle{ B_i }[/math]发生时,即当pivot恰为数组[math]\displaystyle{ A }[/math]中第[math]\displaystyle{ i }[/math]小的元素, 算法会将[math]\displaystyle{ A }[/math]中比pivot小的[math]\displaystyle{ (i-1) }[/math]个元素放入子数组[math]\displaystyle{ L }[/math]、将比pivot大的[math]\displaystyle{ (n-i) }[/math]个元素放入子数组[math]\displaystyle{ R }[/math],这总共会花费[math]\displaystyle{ n-1 }[/math]次比较。 而且,由于[math]\displaystyle{ L }[/math][math]\displaystyle{ R }[/math]的内部元素之间分别保持了原相对顺序,因此不难验证[math]\displaystyle{ L }[/math][math]\displaystyle{ R }[/math]各自内部元素的相对顺序,分别同分布于[math]\displaystyle{ (i-1) }[/math]元均匀随机排列和[math]\displaystyle{ (n-i) }[/math]元均匀随机排列。 因此,在[math]\displaystyle{ B_i }[/math]发生的情况下,递归调用QSort[math]\displaystyle{ (L) }[/math]QSort[math]\displaystyle{ (R) }[/math]各自所使用的总比较次数分别为[math]\displaystyle{ X_{i-1} }[/math][math]\displaystyle{ X_{n-i} }[/math]。 综上所述,有如下恒等关系:

[math]\displaystyle{ \mathbb{E}[X_n\mid B_i] = \mathbb{E}[n-1+X_{i-1}+X_{n-i}] }[/math].

因此,上述全期望因此可被计算如下:

[math]\displaystyle{ \begin{align} t(n) = \mathbb{E}[X_n] &= \frac{1}{n}\sum_{i=1}^n\mathbb{E}[X_n\mid B_i]\\ &= \frac{1}{n}\sum_{i=1}^n\mathbb{E}[n-1+X_{i-1}+X_{n-i}]\\ &= n-1+\frac{2}{n}\sum_{i=0}^{n-1}\mathbb{E}[X_{i}] &\text{(linearity of expectation)}\\ &= n-1+\frac{2}{n}\sum_{i=0}^{n-1}t(i). \end{align} }[/math]

我们因此建立了平均复杂度[math]\displaystyle{ t(n)=\mathbb{E}[X_n] }[/math]的如下递归式:

[math]\displaystyle{ \begin{align} t(n) &= n-1+\frac{2}{n}\sum_{i=0}^{n-1}t(i) && \text{if }n\gt 1;\\ t(n) &= 0 && \text{if }0\le n\le 1. \end{align} }[/math]

我们有若干种方法从这一递归式获得关于[math]\displaystyle{ t(n)=\mathbb{E}[X_n] }[/math]的真相:

  • 一种是使用生成函数等工具来求解这样的递归方程,例如使用本学期组合数学课上的分析,最终可精确解出[math]\displaystyle{ t(n)=2(n+1)H(n)-4n }[/math],这里[math]\displaystyle{ H(n)=\sum_{k=1}^{n}\frac{1}{k} }[/math]是第[math]\displaystyle{ n }[/math]调和数
  • 另一种是采用数学归纳法来对我们猜想的关于[math]\displaystyle{ t(n) }[/math]的界进行验证,例如从[math]\displaystyle{ t(n)\le c n \ln n }[/math]的归纳假设出发,令[math]\displaystyle{ c }[/math]尽量小,不难验证[math]\displaystyle{ t(n)\le 4 n \ln n }[/math]

快速排序算法的平均复杂度分析 II(基于期望的线性)

假设输入数组[math]\displaystyle{ A }[/math]中的元素,在从小到大排序之后为[math]\displaystyle{ a_1\lt a_2\lt \cdots a_n }[/math]。而令输入[math]\displaystyle{ A }[/math]为该[math]\displaystyle{ n }[/math]个数字的随机排列。

令随机变量[math]\displaystyle{ X }[/math]表示在该随机输入[math]\displaystyle{ A }[/math]下,快速排序算法使用的总比较次数。我们希望分析得到期望[math]\displaystyle{ \mathbb{E}[X] }[/math]的上界。

[math]\displaystyle{ 1\le i\lt j\le n }[/math],令布尔值随机变量[math]\displaystyle{ I_{ij}=I(A_{ij})\in\{0,1\} }[/math]指示如下事件的发生:

  • [math]\displaystyle{ A_{ij} }[/math]:元素[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]在算法运行过程中被比较了。

容易验证:在算法运行过程中,任何元素对[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]之间至多只会进行一次比较。 因此总比较次数[math]\displaystyle{ X }[/math]可被计算如下:

[math]\displaystyle{ X=\sum_{i\lt j}I_{ij} }[/math].

根据期望的线性:

[math]\displaystyle{ \mathbb{E}[X]=\sum_{i\lt j}\mathbb{E}[I_{ij}]=\sum_{i\lt j}\Pr(A_{ij}) }[/math].

因此接下来,仅需要针对每一对具体的[math]\displaystyle{ 1\le i\lt j\le n }[/math],计算概率:

[math]\displaystyle{ \Pr(A_{ij})=\Pr(a_i\text{和}a_j\text{在算法中进行了比较}) }[/math].

定下任意一对具体的[math]\displaystyle{ 1\le i\lt j\le n }[/math]。 在算法运行之初(顶层递归调用),元素[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]显然有[math]\displaystyle{ a_i\lt a_j }[/math]、且同属于当前递归调用的输入数组[math]\displaystyle{ A }[/math]。 此时根据pivot的选取,有如下三种可能的情况:

  1. pivot刚好选中[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]之一,此时[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]之间必被比较(因为pivot会与当前数组内的所有元素进行比较),因此事件[math]\displaystyle{ A_{ij} }[/math]确定发生;
  2. [math]\displaystyle{ a_i\lt }[/math]pivot[math]\displaystyle{ \lt a_j }[/math],即pivot取值在[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]之间,此时[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]会被大小居于其中间的pivot元素分别分流到子数组[math]\displaystyle{ L }[/math][math]\displaystyle{ R }[/math]中,且在之后的递归调用中永不再见,因此不会被比较,事件[math]\displaystyle{ A_{ij} }[/math]确定不发生;
  3. pivot选中了比[math]\displaystyle{ a_i }[/math]更小或者比[math]\displaystyle{ a_j }[/math]更大的元素,在此情况下[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math],连同它们之间的所有元素[math]\displaystyle{ \{a_k\mid i\lt k\lt j\} }[/math],都会被分到同一个子数组[math]\displaystyle{ L }[/math]或者[math]\displaystyle{ R }[/math]中,而此时[math]\displaystyle{ A_{ij} }[/math]的发生与否尚未确定,需要递归至下一层(而且输入是[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]所同属的那个子数组)再确定。

不难看出,上述三种情况的分析,对于任意[math]\displaystyle{ A_{ij} }[/math]发生与否尚未确定的当前递归调用(即[math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]同属于当前递归调用的输入数组),都仍然是成立的。 从而,上述情况分类可不断递归进行下去,直至事件[math]\displaystyle{ A_{ij} }[/math]的发生与否被完全确定下来。

因此,可以得出:[math]\displaystyle{ A_{ij} }[/math]发生,当且仅当在上述情况(1)或(2)之一发生的前提下有(1)发生。 除此之外,如下两个观察通过递归验证易得:

  • [math]\displaystyle{ a_i }[/math][math]\displaystyle{ a_j }[/math]同属于当前递归调用的输入数组时,它们之间的所有元素[math]\displaystyle{ \{a_k\mid i\lt k\lt j\} }[/math]也属于该数组;
  • 在任何递归调用中,pivot始终在当前输入数组中均匀分布。

综上可得:

[math]\displaystyle{ \Pr(A_{ij})=\Pr(\mathsf{pivot}\in\{a_i,a_j\}\mid\mathsf{pivot}\in\{a_i,a_{i+1},\ldots,a_{j}\})=\frac{2}{j-i+1} }[/math].

算法总比较次数的期望[math]\displaystyle{ \mathbb{E}[X] }[/math]可被计算如下:

[math]\displaystyle{ \begin{align} \mathbb{E}\left[X\right] &= \sum_{i\lt j}\Pr(A_{ij})\\ &\le \sum_{i=1}^n\sum_{j=i}^n\frac{2}{j-i+1}\\ &= \sum_{i=1}^n\sum_{k=2}^{n-i+1}\frac{2}{k} & & (\mbox{Let }k=j-i+1)\\ &\le \sum_{i=1}^n\sum_{k=1}^{n}\frac{2}{k}\\ &= 2n\sum_{k=1}^{n}\frac{1}{k}\\ &= 2n H(n). \end{align} }[/math]

此处[math]\displaystyle{ H(n)=\sum_{k=1}^{n}\frac{1}{k} }[/math]是第[math]\displaystyle{ n }[/math]调和数