For example we have the array like this:

[, , , , , ]

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

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

Then sort according to the last digit:

[, , , , , ]

Then using second last digit to the sort:

[, , , , , ]

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

[, , , , , ]

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))

[Algorithm] Radix Sort Algorithm的更多相关文章

  1. C++<algorithm>中sort的比较函数写法(转)

    转自:http://www.wl566.com/biancheng/98907.html C++<algorithm>中sort的比较函数写法,有需要的朋友可以参考下. 定义排序函数: 方 ...

  2. [Algorithm] Heap data structure and heap sort algorithm

    Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...

  3. [Algorithms] Insertion sort algorithm using TypeScript

    Insertion sort is a very intuitive algorithm as humans use this pattern naturally when sorting cards ...

  4. 数据结构与算法---排序算法(Sort Algorithm)

    排序算法的介绍 排序也称排序算法 (Sort Algorithm),排序是将一组数据,依指定的顺序进行排列的过程. 排序的分类 1) 内部排序: 指将需要处理的所有数据都加载 到内部存储器(内存)中进 ...

  5. super fast sort algorithm in js

    super fast sort algorithm in js sort algorithm Promise.race (return the fast one) Async / Await // c ...

  6. [Algorithms] Radix Sort

    Radix sort is another linear time sorting algorithm. It sorts (using another sorting subroutine) the ...

  7. [MIT6.006] 7. Counting Sort, Radix Sort, Lower Bounds for Sorting 基数排序,基数排序,排序下界

    在前6节课讲的排序方法(冒泡排序,归并排序,选择排序,插入排序,快速排序,堆排序,二分搜索树排序和AVL排序)都是属于对比模型(Comparison Model).对比模型的特点如下: 所有输入ite ...

  8. 基数排序(radix sort)

    #include<iostream> #include<ctime> #include <stdio.h> #include<cstring> #inc ...

  9. 经典排序算法 - 基数排序Radix sort

    经典排序算法 - 基数排序Radix sort 原理类似桶排序,这里总是须要10个桶,多次使用 首先以个位数的值进行装桶,即个位数为1则放入1号桶,为9则放入9号桶,临时忽视十位数 比如 待排序数组[ ...

随机推荐

  1. Luogu 4492 [HAOI2018]苹果树 组合数

    https://www.luogu.org/problemnew/show/P4492 找每个编号的点的父边的贡献,组合数和阶乘就能算了. 我考场上怎么就是没想到呢. 调了好久好久好久好久调不出来,样 ...

  2. Android之安全机制

    根据android四大框架来解说安全机制 代码安全 java不同于C/C++,java是解释性语言,存在代码被反编译的隐患: 默认混淆器为proguard,最新版本为4.7: proguard还可用来 ...

  3. [CodeVS1243]网络提速

    题目大意: 有n个点的连通图,有m次可以将某一条边权值减半的机会. 不同的机会可以叠加作用于同一条边. 求1~n的最短路. 思路: 拆点,记录1到每个点在使用不同次数的机会后的最短路,然后直接跑Dij ...

  4. 【JavaScript代码实现一】数组去重

    function arrayNoDupulate(array) { var hash = {}; var result = []; for(var i=0;i<array.length;i++) ...

  5. Jmeter实现webservice的接口测试

    前提条件 测试的URL:http://ws.webxml.com.cn/WebServices/WeatherWS.asmx 测试接口:getSupportCityString 获取城市的编码:htt ...

  6. linux内核 asmlinkage宏

    http://blog.chinaunix.net/uid-7390305-id-2057287.html

  7. 从 n 个数字中选出 m 个不同的数字,保证这 m 个数字是等概率的

    问题如上. 这是我被面试的一个题目. 我的第一反应给出的解决的方法是.开启  n 个线程并标记序号,各个线程打印出它的序号.直到有 m 个线程被调度时,停止全部线程. 打印出的序号即是 m 个等概率出 ...

  8. 转 UIAlertView 不显示、屏幕变灰

    UIAlertView 不显示.屏幕变灰 SvenFang 票 在 [[NSNotificationCenter defaultCenter] addObserver:self selector:@s ...

  9. extjs 动态设定 DateField 最大值 最小值

    yxrqDate.minValue = new Date();yxrqDate.maxValue = new Date(9000,1,1);yxrqDate.validate(); //var pic ...

  10. go语言 defer 高级

    go语言defer语句的用法 defer的语法 defer后面必须是函数调用语句,不能是其他语句,否则编译器会出错. package main import "log" func ...