RadixSort is a non-comparison based sorting algorithm that sorts integers by processing
individual digits. It processes the digits from least significant to most significant
(LSD Radix Sort) or from most significant to least significant (MSD Radix Sort).
This implementation uses LSD (Least Significant Digit) Radix Sort, which processes
digits from right to left. The algorithm uses counting sort as a subroutine to sort
the array based on each digit.
Radix sort is particularly efficient for sorting integers with a fixed number of digits.
The time complexity is O(d * (n + k)) where n is the number of elements, d is the number
of digits in the maximum number, and k is the range of each digit (typically 10 for decimal).
The space complexity is O(n + k).
Note: This implementation works with non-negative integers. For negative numbers,
they are handled by separating them, sorting, and recombining.
Example
constradixSort = newRadixSort([170, 45, 75, 90, 802, 24, 2, 66]); radixSort.sort(); // returns new array with [2, 24, 45, 66, 75, 90, 170, 802] // or RadixSort.sort([170, 45, 75, 90, 802, 24, 2, 66]); // returns new array with [2, 24, 45, 66, 75, 90, 170, 802]
RadixSort is a non-comparison based sorting algorithm that sorts integers by processing individual digits. It processes the digits from least significant to most significant (LSD Radix Sort) or from most significant to least significant (MSD Radix Sort).
This implementation uses LSD (Least Significant Digit) Radix Sort, which processes digits from right to left. The algorithm uses counting sort as a subroutine to sort the array based on each digit.
Radix sort is particularly efficient for sorting integers with a fixed number of digits. The time complexity is O(d * (n + k)) where n is the number of elements, d is the number of digits in the maximum number, and k is the range of each digit (typically 10 for decimal). The space complexity is O(n + k).
Note: This implementation works with non-negative integers. For negative numbers, they are handled by separating them, sorting, and recombining.
Example
Example