cstutoringcenter.com logo
E-mail:Password:

Become a premier member today to gain access to exclusive
member benefits! Just $5.00 to join FOR LIFE!






Radix sorting involves looking at a radix (or digit) of a number and placing it in an array of linked lists to sort it.

Algorithm for radix sorting:
1.	Look at the rightmost digit.
2.	Assign the full number to that digits index.
3.	Look at the next digit to the left FROM the current 
        sorted array.  IF there is no digit, pad a 0.
4.	REPEAT STEP 3 UNTIL all numbers have been sorted.

Let's see a step by step example of a radix sort of the following set of unsorted numbers. The bold digits here represent the first digit to look at when attempting to sort the list. You must also append it to the end of that linked list in the array.

212  21  72  5  431  898  616  24  9

Step 1:
0
1	21 -> 431
2	212 -> 72
3
4	24
5	05
6	616
7
8	898
9	09

Step 2: (working from step 1)
0	005 -> 009
1	212 -> 616
2	021 -> 024
3	431
4
5
6
7	072
8
9	898

Step 3: (working from step 2)
0	5 -> 9 -> 21 -> 24 -> 72
1
2	212
3
4	431
5
6	616
7
8	898
9

Step 3 is the final step and the list is sorted.

The benefits of a radix sort is the fact that it can be done by pencil and paper. It also only contains a fixed data structure (an array of size 10). The downside of radix sort is that it takes time to implement since you may manually go through numerous steps to sort the list depending on how many numbers you have to sort.

Here is another example of radix sort, this time using numbers up to 4 digits in length. You will notice something interesting hereĀ…

58  99  999  47  200  101  1002  12  1111

Step 1:
0	200
1	101 -> 1111
2	1002 -> 12
3
4
5
6
7	47
8	58
9	99 -> 999

Step 2: (working from step 1)
0	200 -> 101 -> 1002
1	1111 -> 012
2
3
4	047
5	058
6
7
8
9	099 -> 999

Step 3: (working from step 2)
0	1002 -> 0012 -> 0047 -> 0058 -> 0099
1	0101 -> 1111
2	0200
3
4
5
6
7
8
9	0999

Step 4: (working from step 3)
0	12 -> 47 -> 58 -> 99 -> 101 -> 200 -> 999
1	1002 -> 1111
2
3
4
5
6
7
8
9

Step 4 is the final step here. Notice however that the index 0 goes from 0 to 999 while 1 goes from 1000 to 1999 etc...