Class Radix
java.lang.Object
topics.sorting.radix.Radix
- All Implemented Interfaces:
SortingAlgorithm
Radix Sort (LSD - Least Significant Digit)
A non-comparative integer sorting algorithm that groups keys by individual digits that share the same significant position and value. This implementation processes digits from the Least Significant Digit (units) to the Most Significant Digit using 10 Base-10 Queues (Buckets).
Algorithm Steps
- Identify the maximum value in the array to determine the max digit count (K).
- For each digit position (Units, Tens, Hundreds...), distribute the elements into 10 buckets based on their digit at that position.
- Re-collect the elements from the buckets back into the original array, preserving their stable order.
- Repeat for the next significant digit.
Complexity Analysis
- Time Complexity:
O(K × N)strictly in all cases, whereNis the number of elements andKis the number of digits in the largest number. IfKis small, it behaves almost linearly. - Space Complexity:
O(N + Base)- Requires additional memory to store the elements inside the buckets (Queues). - Stability: Yes - It is strictly required to be stable for the digit-by-digit sorting logic to work correctly.
- Author:
- vicegd
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Radix
public Radix()
-
-
Method Details
-
sort
public void sort(int[] elements) Description copied from interface:SortingAlgorithmSorts the elements in-place silently.- Specified by:
sortin interfaceSortingAlgorithm- Parameters:
elements- The array of integers to be sorted.
-
sort
public void sort(int[] elements, boolean trace) Description copied from interface:SortingAlgorithmSorts the elements in-place, optionally emitting step-by-step traces to visualize the algorithmic progression.- Specified by:
sortin interfaceSortingAlgorithm- Parameters:
elements- The array of integers to be sorted.trace- Iftrue, logs the internal state during execution.
-