[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 @   Zhentiw  阅读(303)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2018-03-14 [HTML 5] Styling with ARIA
2017-03-14 [Node.js] Initialize a LoopBack Node.js Project through the CLI
2017-03-14 [Angular] Pipes as providers
2017-03-14 [Angular] Create a custom pipe
2017-03-14 [Angular] Create a simple *ngFor
2016-03-14 [Node.js] Use "prestart" in scripts
2016-03-14 [Node.js] Using ES6 and beyond with Node.js
点击右上角即可分享
微信分享提示