Radix Sort is a non-comparative sorting algorithm that sorts integers by processing individual digits.
Unlike comparison-based algorithms like Quick Sort or Merge Sort, Radix Sort groups numbers by their digit values, starting from the least significant digit (LSD) to the most significant digit (MSD).
It uses a stable sorting subroutine, typically Counting Sort, to sort numbers at each digit level, ensuring that the relative order of numbers with the same digit value is preserved across iterations. This stability is crucial for maintaining the overall order when processing subsequent digits.
The algorithm begins by initializing a series of buckets or buffers to count the occurrences of each digit (0-9 for decimal numbers) at a given place value (units, tens, hundreds, etc.).
For each digit place, the algorithm iterates through the entire list of numbers, extracting the relevant digit, and updating the count in the corresponding bucket. After counting, a prefix sum or cumulative count is computed, transforming the count array into a position array that indicates where each digit should be placed in the output array.
In the final phase, the numbers are rearranged based on the prefix sum array to ensure they are sorted according to the current digit. This process is repeated for each digit place, progressively refining the order of the list.
At the end of the process, the numbers are sorted in ascending order.
Radix Sort's efficiency comes from its linear time complexity for fixed-width integers, making it particularly effective for sorting large datasets with uniformly distributed keys; its performance can be affected by the number of digits and the base used for digit extraction, as well as the additional memory required for the counting and prefix sum arrays.
Complete Code
The complete code for the WebGPU (JavaScript) and the WGSL compute shader.
Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.