Radix Sort

To illustrate the radix sort algorithm we will sort the sequence S0 = {32, 100, 11, 554, 626, 122, 87, 963, 265, 108, 9}. We start by distributing elements of S0 by the value of 0-place digit (the one's place):

bucket 0:  100
bucket 1:  11
bucket 2:  32, 122
bucket 3:  963
bucket 4:  554
bucket 5:  265
bucket 6:  626
bucket 7:  87
bucket 8:  108
bucket 9:  9


Stitch the bucket lists to create S1 = {100, 11, 32, 122, 963, 554, 265, 626, 87, 108, 9}. Distribute elements of S1 by the value of 1-place digit (the ten's place):

bucket 0: 100, 108, 9
bucket 1: 11
bucket 2: 122, 626
bucket 3: 32
bucket 4:
bucket 5: 554
bucket 6: 963, 265
bucket 7:
bucket 8: 87
bucket 9:


Stitch the bucket lists to create S2 = {100, 108, 9, 11, 122, 626, 32, 554, 963, 265, 87}. Distribute elements of S2 by the value of 2-place digit (the hundred's place):

bucket 0: 9, 11, 32, 87
bucket 1: 100, 108, 122
bucket 2: 265
bucket 3:
bucket 4:
bucket 5: 554
bucket 6: 626
bucket 7:
bucket 8:
bucket 9: 963


Stitch the bucket lists to create S3 = {9, 11, 32, 87, 100, 108, 122, 265, 554, 626, 963}. The list is sorted.

posted @ 2020-05-01 00:02  Jasper2003  阅读(197)  评论(0编辑  收藏  举报