Very fast at sorting many integers. Time complexity is: O(n+k) n = length of list k = range of values (max - min) The demonstration is sorting 100,000 numbers ranging from -10,000 to 10,000, inclusive.
This is a version of counting sort that can work with negative values. It does this by subtracting the minimum value of the input when indexing the count list. As a side effect, the `c` list contains the quantity of each number in the list. To get the count of a number, take the number you're interested in, subtract the variable `o` from it, and get the value at that index in the `c` list. This algorithm works by counting the amount of each value in the input, and using that to figure out where it will be in the sorted list, allowing it to scale far better than comparison based algorithms. Because of this, it only works with integer values. (So, 10 and 4 are ok, but 2.5 and 3.1 are not) I used one-letter variable names because Scratch is a bit silly in that shorter and less readable names make programs run better.