Introduction to counting sort


Counting sort is a non-comparison-based sorting algorithm that operates by counting the number of occurrences of each unique element in the input list and using this information to place each element in the correct position in the output list. It is particularly useful when the range of input elements is known and relatively small compared to the number of elements to be sorted.

Example

Let's say you were a teacher assigned the task of sorting students' answer sheets, with scores out of 100. However, the catch is that there is a large number of students. You could use some of the sorts we studied earlier, but they would be quite time-consuming, since you would need to make many comparisons.

Liking the course? Check our discounted plans to continue learning.