We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 30f9b4a commit d8fcc15Copy full SHA for d8fcc15
zh-hans/basics_sorting/quick_sort.md
@@ -142,7 +142,7 @@ public class Sort {
142
}
143
```
144
145
-容易出错的地方在于当前 partition 结束时未将 $$i$$ 和 $$m$$ 交换。比较`alist[i]`和`alist[l]`时只能使用`<`而不是`<=`! 因为只有取`<`才能进入收敛条件,`<=`则可能会出现死循环,因为在`=`时第一个元素可能保持不变进而产生死循环。
+容易出错的地方在于当前 partition 结束时未将 $$i$$ 和 $$m$$ 交换。
146
147
相应的结果输出为:
148
@@ -182,6 +182,8 @@ public class Sort {
182
183
这样一来对于数组元素均相等的情形下,每次 partition 恰好在中间元素,故共递归调用 $$\log n$$ 次,每层递归调用进行 partition 操作的比较次数总和近似为 $$n$$. 故总计需 $$n \log n$$ 次比较。[^programming_pearls]
184
185
+可以推断出在最坏情况下,即数组本来就有序,这种方法仍然无法避免 $$O(n^2)$$ 的厄运... 即便如此,这种两边推进的方法大大提高了分区的效率,减少了 swap 的次数。
186
+
187
### Python
188
189
```python
0 commit comments