首页 > 代码库 > Counting Sort

Counting Sort

1. Counting Sort doesn‘t work for negative number.

2. Counting Sort assumes that each element is SMALL INTEGER.

3. Time Complexity is O(Maximum value - Minimum value).

4. It is useful when the difference is not large

 

Algorithm:

1. Create an array of the size of the Maximun Value + 1.

2. Count each element.

3. Add up all elements.

4. Put them back to the result.

https://www.youtube.com/watch?v=o3FUC6l89tM

Counting Sort