mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 22:46:07 +00:00
Simplify the contents of the sorting algorithms.
This commit is contained in:
@@ -181,17 +181,9 @@ $$
|
||||
|
||||
**时间复杂度 $O(n + m)$** :涉及遍历 `nums` 和遍历 `counter` ,都使用线性时间。一般情况下 $n \gg m$ ,此时使用线性 $O(n)$ 时间。
|
||||
|
||||
**空间复杂度 $O(n + m)$** :数组 `res` 和 `counter` 长度分别为 $n$ , $m$ 。
|
||||
**空间复杂度 $O(n + m)$** :借助了长度分别为 $n$ , $m$ 的数组 `res` 和 `counter` ,是“非原地排序”;
|
||||
|
||||
**非原地排序**:借助了辅助数组 `counter` 和结果数组 `res` 的额外空间。
|
||||
|
||||
**稳定排序**:倒序遍历 `nums` 保持了相等元素的相对位置。
|
||||
|
||||
**非自适应排序**:与元素分布无关。
|
||||
|
||||
!!! question "为什么是稳定排序?"
|
||||
|
||||
由于向 `res` 中填充元素的顺序是“从右向左”的,因此倒序遍历 `nums` 可以避免改变相等元素之间的相对位置,从而实现“稳定排序”;其实正序遍历 `nums` 也可以得到正确的排序结果,但结果“非稳定”。
|
||||
**稳定排序**:由于向 `res` 中填充元素的顺序是“从右向左”的,因此倒序遍历 `nums` 可以避免改变相等元素之间的相对位置,从而实现“稳定排序”;其实正序遍历 `nums` 也可以得到正确的排序结果,但结果“非稳定”。
|
||||
|
||||
## 局限性
|
||||
|
||||
|
||||
Reference in New Issue
Block a user