Counting Sort can be insanely fast - faster than O(nlogn). It only works on integers, or other discrete things.
Here's how it works:
1. Loop through the array, counting the number of times each integer appears. Also keep track of the the smallest and biggest integers in the array. This takes O(n) time.
2. Iterate from the smallest integer to the biggest integer, adding each value the corrent number of times. This takes O(maxval - minval) time.
Here's the code:
Time Complexity O(n+maxval - minval)
Space Complexity O(n)