Iteration

Counting Sort

Sorting

Counting Sort can be insanely fast - faster than O(nlogn)O(n \log n). It only works on integers, or other discrete things.

First Few Test Cases:

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)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)O(\texttt{maxval - minval}) time.

Here's the code:

Time Complexity O(n+maxval - minval)O(n + \texttt{maxval - minval})

Space Complexity O(n)O(n)

Mark as Completed:
Submits:
countingSort
Test your code to get an output here!
countingSort(
)
Test your code to get an output here!