Counting Sort | Counting Sort in C++|

Опубликовано: 04 Март 2026
на канале: PROJECT TUNNEL
18
0

Counting Sort is a non-comparative sorting algorithm that works well for integers with a limited range. Unlike comparison-based algorithms (such as quicksort or mergesort), counting sort exploits the fact that the input elements have a restricted range to achieve linear time complexity.
Counting Sort is particularly efficient when the range of input values is not significantly larger than the number of elements to be sorted. Its time complexity is O(n + k), where n is the number of elements in the input array, and k is the range of input values.


However, Counting Sort is not suitable for sorting data with large ranges or when dealing with floating-point numbers. It is a stable sort, meaning that the relative order of equal elements is preserved in the sorted output.