[Algorithm] Radix Sort Algorithm

For example we have the array like this:

[53, 89, 150, 36, 633, 233]

 

First step is using Counting sort for last digit, in our example is:

[53, 89, 150, 36, 633, 233]
[3, 9, 0, 6, 3, 3]

Then sort according to the last digit:

[150, 53, 633, 233, 36, 89]

 

Then using second last digit to the sort:

[633, 233, 36, 150, 53, 89]

 

Last using the last digist to do the sort, and using '0' if missing the digit:

[36, 53, 89, 150, 233, 633]

The whole array should be sorted.

 

Time complexiity:

n = 6: array length is 6

d = 3: max digit for number is 3

b = 10, we use 10 based counting [0, 1,2,3...9]

For each step it takes O(n+b) to do the sorting

Then for the whole algorithm is O(d * (n+b))

posted @ 2019-03-14 15:45  Zhentiw  阅读(302)  评论(0编辑  收藏  举报