# Radix Sort – Data Structures and Algorithms

Radix Sort stands as a linear sorting technique that sorts elements by methodically examining them digit by digit. This algorithm proves to be highly efficient when sorting integers or strings featuring fixed-size keys.

Instead of directly comparing elements, It actively distributes the elements into buckets according to the value of each digit. Through successive sorting of elements by their significant digits, starting from the least significant and progressing to the most significant, it effectively attains the ultimate sorted arrangement.

At the core of the Radix Sort lies the concept of place value. Moreover, the algorithm operates on the premise that sorting numbers digit by digit ultimately leads to a completely sorted list. Additionally, It showcases its adaptability through various implementations, including the Least Significant Digit (LSD) Radix Sort and the Most Significant Digit (MSD) Radix Sort, each offering unique advantages.

Simplified steps:

1. Firstly, find the maximum number in the array to determine the number of digits.
2. To preceed, iterate through each digit position, starting from the least significant digit (rightmost).
3. Use counting sort to sort the array based on the current digit position.
4. Lastly, Repeat the counting sort process for all digit positions, from least to most significant.

## Working of Radix Sort Algorithm

Let’s illustrate the Radix Sort algorithm using the following example:

Array: [17, 11, 9, 14, 21]

• Pass 1: To Begin with, the initial array state and identify the maximum number (21) for digit count. Sort by the least significant digit.
• Pass 2: Then, Start with the array sorted by the least significant digit. Sort by the next significant digit.
• Pass 3: at Last, Begin with the array sorted by the first two digits. Sort by the next significant digit.

## Complexity Analysis

### Time Complexity

The time complexity of Radix Sort is O(k * n), where ‘k’ is the number of digits in the maximum number and ‘n’ is the number of elements.

### Space Complexity

The auxiliary space complexity of Radix Sort is O(n), primarily due to the usage of buckets to temporarily store elements during sorting.

In summary, Radix Sort proves its efficiency by leveraging digit-based distribution for sorting. By assigning elements to buckets based on individual digit values, this algorithm ensures stable sorting, maintaining the order of equal elements. It excels in sorting integers with a narrow value range, capitalizing on its linear time complexity for such cases. Despite its suitability for specific scenarios, Radix Sort’s space usage can be a limitation in larger datasets. Ultimately, Radix Sort stands as a valuable tool within its domain, showcasing effectiveness and adaptability.