In: Computer Science
Give an example of how Radix sort works
As an example, let's sort this list : 82, 901, 100, 12, 150, 77, 55, 23
Step1. Simply Define a queue(0 to 9)
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Step 2: Insert all the numbers in the list to queue.Based on the One placed digit of every number
ie. in 0 we insert 100,150 (since their one digit place is 0) , in 1 we insert 901(since their one digit is 1) and so on.
150 100 |
901 |
12 82 |
23 | 55 | 77 | ||||
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Group all the numbers from queue in the order in which they are inserted
new list=100, 150, 901, 82, 12, 23, 55, 77
Step 3: Insert all the numbers in the new list to queue.Based on the Two placed digit of every number
ie. in 0 we insert 100,901 (since their two digit place is 0) , in 1 we insert 12 (since their two digit is 1) and so on.
901 100 |
12 |
23 |
55 150 |
77 | 82 | ||||
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Group all the numbers from queue in the order in which they are inserted
new list=100, 901,12,23,150,55,77,82
Step 4: Insert all the numbers in the new list to queue.Based on the 3 placed digit of every number
ie. in 0 we insert 82,77 etc (since their 3 digit place is 0) , in 1 we insert 100,150 (since their 3 digit is 1) and so on.
82 77 55 23 12 |
150 100 |
901 | |||||||
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Group all the numbers from queue in the order in which they are inserted
new list=12,23,55,77,82,100,150,901