0% found this document useful (0 votes)
15 views3 pages

3 Radix-Sort

Data structure sorting like merge sort, select sort like that.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

3 Radix-Sort

Data structure sorting like merge sort, select sort like that.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Radix Sort Algorithm

Radix sort is a linear sorting algorithm designed specifically for


integers. It sorts numbers digit by digit, starting from the least
significant digit (the rightmost digit) and moving towards the most
significant digit (the leftmost digit). This process involves multiple
passes over the data, using a stable sorting algorithm (like counting
sort) for each digit.

Characteristics
 Non-Comparative: Unlike traditional sorting algorithms (e.g.,
quicksort, mergesort) that compare elements directly, Radix sort
organizes elements based on their digit values.
 Stable: Radix sort preserves the order of equal elements,
making it suitable for applications where the order of similar
elements is significant.
 Linear Time Complexity: The average and worst-case time
complexity can be O(d * (n + k)), where:
o d is the number of digits in the largest number.
o n is the number of elements in the array.
o k is the range of the input (for decimal digits, this would
be 0-9).

Steps of Radix Sort


1. Identify the Maximum Value:
o Determine the maximum number in the array to find out
how many digits it has.
2. Iterate Over Each Digit:
o For each digit (starting from the least significant):
 Sort the Array: Use a stable sorting algorithm to
sort the numbers based on the current digit.
3. Repeat Until All Digits are Processed:
o Continue the sorting process for all digits until the most
significant digit is processed.

Example
 Input: [170, 45, 75, 90, 802, 24, 2, 66]
 Pass 1 (Least Significant Digit): Sort based on the unit place
→ [170, 90, 802, 2, 24, 45, 75, 66]
 Pass 2: Sort based on the tens place → [170, 802, 2, 24, 45, 75,
90, 66]
 Pass 3 (Most Significant Digit): Sort based on the hundreds
place → [2, 24, 45, 66, 75, 90, 170, 802]

Advantages
 Efficiency: Radix sort can be faster than comparison-based sorts
(like quicksort or mergesort) for integers with a limited range of
digits.
 Non-Comparison Based: It doesn't compare elements directly,
which can lead to better performance in specific scenarios.
Disadvantages
 Space Complexity: Requires additional space for counting and
temporary arrays, making it less memory-efficient than in-place
algorithms.
 Limited to Integers: Primarily used for integers or strings; not
applicable for all data types without modification.
 Dependency on Digit Range: Performance can degrade if the
range of digits (or characters) is large.

You might also like