Skip to content

Commit 92fceb0

Browse files
committed
counting sort
1 parent c0d6bb3 commit 92fceb0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/8.counting_sort.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
## 概述
44

55
计数排序的核心在于将输入的数据值转化为键存储在额外开辟的数据空间中。作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范围的整数。
6+
7+
8+
## 算法步骤
9+
10+
1. 花 O(n)的时间扫描一下整个序列 A,获取最小值 min 和最大值 max
11+
2. 开辟一块新的空间创建新的数组 B,长度为(max-min+1)
12+
3. 数组B 中 index 的元素记录的值是 A中某元素出现的次数
13+
4. 最后输出目标整数序列,具体的逻辑是遍历数组 B,输出相应元素以及对应的个数。

0 commit comments

Comments
 (0)