Update the sorting algorithms.

This commit is contained in:
krahets
2023-05-24 00:05:12 +08:00
parent a2d2011c78
commit 588980af86
7 changed files with 23 additions and 38 deletions
+3 -5
View File
@@ -164,8 +164,6 @@
## 算法特性
各轮“冒泡”遍历的数组长度依次为 $n - 1$ , $n - 2$ , $\cdots$ , $2$ , $1$ ,总和为 $\frac{(n - 1) n}{2}$ **因此时间复杂度为 $O(n^2)$** 。在引入 `flag` 优化后,最佳时间复杂度可达到 $O(n)$ **是“自适应排序”**
指针 $i$ , $j$ 使用常数大小的额外空间,**因此空间复杂度为 $O(1)$ ,是“原地排序**。
由于在“冒泡”中遇到相等元素不交换,**因此冒泡排序是“稳定排序”**。
- **时间复杂度为 $O(n^2)$ 、自适应排序** 各轮“冒泡”遍历的数组长度依次为 $n - 1$ , $n - 2$ , $\cdots$ , $2$ , $1$ ,总和为 $\frac{(n - 1) n}{2}$ 。在引入 `flag` 优化后,最佳时间复杂度可达到 $O(n)$ 。
- **空间复杂度为 $O(1)$ 、原地排序**:指针 $i$ , $j$ 使用常数大小的额外空间。
- **稳定排序**:由于在“冒泡”中遇到相等元素不交换