mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-15 16:36:06 +00:00
Update the sorting algorithms.
This commit is contained in:
@@ -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$ 使用常数大小的额外空间。
|
||||
- **稳定排序**:由于在“冒泡”中遇到相等元素不交换。
|
||||
|
||||
Reference in New Issue
Block a user