Counting Sort is a non-comparison-based sorting algorithm that efficiently sorts a collection of integers. It works by counting the occurrences of each unique value in the input array, then using this information to determine the position of each element in the sorted output. This method is particularly effective when the range of input values is not significantly larger than the number of elements to be sorted.
The algorithm begins by creating a count array, where each index corresponds to a value from the input. After populating this count array, it calculates cumulative counts to determine the final positions of each element. Finally, it constructs the sorted array by placing each element in its correct position based on the counts.