counting-sort
Counting sort
When
given an array A with n elements ranging in size from 1 to k

Given array , get counts of each digit

Then insert into array
ChatGPT Explanation
Counting Sort: This algorithm works by counting the number of occurrences of each distinct element in the array and then calculating the prefix sum of the counts to determine the position of each element in the final sorted array. It has a linear time complexity of O(n + k), where k is the range of the input values.
Last updated