Count Sort - Radix Sort Time Complexity Analysis and Space Complexity Analysis
Count Sort - Radix Sort Time Complexity Analysis and Space Complexity Analysis
Count Sort and Radix Sort - Time and Space Complexity Analysis
Faculty of Engineering,
𝟐𝒏𝒅 Year Computer and Systems Department
Intro to count and radix:
Count Sort: A non-comparative sorting algorithm that counts the
occurrences of each element in the input array. It works best when
sorting integers within a known range and is efficient when the range
(k) is not significantly larger than the number of elements (n).
int index = 0;
for (int i = 0; i <= max; i++) {
while (count[i] > 0) {
arr[index++] = i;
count[i]--;
}
}
delete[] count;
}
Radix Sort:
void countSortForRadix(int arr[], int n, int exp) {
int* output = new int[n];
int count[10] = {0};
delete[] output;
}
*Complexity Analysis:
Count Sort:
Time Complexity: O(n+k), where n is the number of elements and k
is the range.
Radix Sort:
Time Complexity: O(d(n+b)), where d is the number of digits and b is
the base (usually 10).
*Use Cases:
Count Sort: Ideal for sorting integers with a limited range (e.g.,
grading).
Radix Sort: Useful for large integer lists when digit length is known
(e.g., sorting IDs).