Skip to content

Commit d8fcc15

Browse files
committed
fix issue billryan#118
1 parent 30f9b4a commit d8fcc15

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

zh-hans/basics_sorting/quick_sort.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public class Sort {
142142
}
143143
```
144144

145-
容易出错的地方在于当前 partition 结束时未将 $$i$$$$m$$ 交换。比较`alist[i]``alist[l]`时只能使用`<`而不是`<=`! 因为只有取`<`才能进入收敛条件,`<=`则可能会出现死循环,因为在`=`时第一个元素可能保持不变进而产生死循环。
145+
容易出错的地方在于当前 partition 结束时未将 $$i$$$$m$$ 交换。
146146

147147
相应的结果输出为:
148148

@@ -182,6 +182,8 @@ public class Sort {
182182

183183
这样一来对于数组元素均相等的情形下,每次 partition 恰好在中间元素,故共递归调用 $$\log n$$ 次,每层递归调用进行 partition 操作的比较次数总和近似为 $$n$$. 故总计需 $$n \log n$$ 次比较。[^programming_pearls]
184184

185+
可以推断出在最坏情况下,即数组本来就有序,这种方法仍然无法避免 $$O(n^2)$$ 的厄运... 即便如此,这种两边推进的方法大大提高了分区的效率,减少了 swap 的次数。
186+
185187
### Python
186188

187189
```python

0 commit comments

Comments
 (0)