Counting Sort

Counting Sort is a non-comparison-based sorting algorithm that sorts integers by counting the occurrences of each distinct value in a range and using this information to place elements in their correct positions. It works in 𝑂(𝑛+π‘˜) time, where 𝑛 is the number of elements and π‘˜ is the range of the input values. Counting Sort is efficient for small ranges of integers but unsuitable for sorting non-integer or large-range data due to its space complexity of 𝑂(π‘˜). It is a stable sorting algorithm when implemented correctly.

  • Time complexity is Linear, i.e. O(n+k)
  • Space complexity is Linear, i.e. O(k)