Skip to content

Commit

Permalink
renew Quicksort
Browse files Browse the repository at this point in the history
  • Loading branch information
linjing-lab committed Aug 20, 2022
1 parent 018e7a2 commit b0aa4b1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/Quicksort.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $$
当我们选取的枢纽每次都是**最大元素**时,就是**最差**情况,待排序的序列为正序或者逆序,每次划分只得到一个比上一次划分少一个记录的子序列,注意另一个为空。如果递归树画出来,它就是一棵斜树。此时需要执行$n‐1$次递归调用,且第 $i$ 次划分需要经过 $n‐i$ 次关键字的比较才能找到第 $i$ 个记录,是枢轴的位置,因此比较次数为:

$$
\sum_{i=1}^{n-1} = (n-1) + (n-2) + + ... + 1 = \frac{n(n-1)}{2}
\sum_{i=1}^{n-1} = (n-1) + (n-2) + ... + 1 = \frac{n(n-1)}{2}
$$

于是时间复杂度为:$O(n^2)$。
Expand Down

0 comments on commit b0aa4b1

Please sign in to comment.