Counting-Sort
Counting-Sort(A,B,k)
let C[0..k] be a new array
for i = 0 to k
C[i] = 0
for j = 1 to A.length
C[A[j]] = C[A[j]] + 1
//C[i] now contains the number of elements equal to i
for i = 1 to k
C[i] = C[i] + C[i-1]
//C[i] now contains the number of elements less than or equal to i
for j = A.length downto 1
B[C[A[j]]] = A[j]
C[A[j]] = C[A[j]] - 1
------<Introduction To Algorithm>
Counting-Sort的更多相关文章
- find out the neighbouring max D_value by counting sort in stack
#include <stdio.h> #include <malloc.h> #define MAX_STACK 10 ; // define the node of stac ...
- counting sort 计数排序
//counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorit ...
- HDU 1718 Rank counting sort解法
本题是利用counting sort的思想去解题. 注意本题,好像利用直接排序,然后查找rank是会直接被判WA的.奇怪的推断系统. 由于分数值的范围是0到100,很小,而student 号码又很大, ...
- 41. First Missing Positive(困难, 用到 counting sort 方法)
Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] ...
- 《算法导论》——计数排序Counting Sort
今天贴出的算法是计数排序Counting Sort.在经过一番挣扎之前,我很纠结,今天这个算法在一些scenarios,并不是最优的算法.最坏情况和最好情况下,时间复杂度差距很大. 代码Countin ...
- [Algorithms] Counting Sort
Counting sort is a linear time sorting algorithm. It is used when all the numbers fall in a fixed ra ...
- 【HackerRank】 The Full Counting Sort
In this challenge you need to print the data that accompanies each integer in a list. In addition, i ...
- 排序算法六:计数排序(Counting sort)
前面介绍的几种排序算法,都是基于不同位置的元素比较,算法平均时间复杂度理论最好值是θ(nlgn). 今天介绍一种新的排序算法,计数排序(Counting sort),计数排序是一个非基于比较的线性时间 ...
- [MIT6.006] 7. Counting Sort, Radix Sort, Lower Bounds for Sorting 基数排序,基数排序,排序下界
在前6节课讲的排序方法(冒泡排序,归并排序,选择排序,插入排序,快速排序,堆排序,二分搜索树排序和AVL排序)都是属于对比模型(Comparison Model).对比模型的特点如下: 所有输入ite ...
- 【算法】计数排序(Counting Sort)(八)
计数排序(Counting Sort) 计数排序不是基于比较的排序算法,其核心在于将输入的数据值转化为键存储在额外开辟的数组空间中. 作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范 ...
随机推荐
- Xcode 字体 设置-- Xcode family没有显示的字体
前往文件夹 -> /Users/user/Library/Developer/Xcode/UserData/FontAndColorThemes/ (user改为自己的用户名) -----如果 ...
- c#访问Oracle问题及解决方法
Q:访问oracle 查询条件带汉字结果集为空的问题 A:数据库连接字符串中加入Unicode=true即可. 如 <add key="DbConnectionString" ...
- javascript 命令方式 测试例子
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- scala学习:apply方法
摘抄两段话: 在明确了方法调用的接收者的情况下,若方法只有一个参数时,调用的时候就可以省略点及括号.如 " to ",实际完整调用是 ".to()".但 &qu ...
- Linux程序包管理初步-yum的使用
何为yum? yum:由yellow dog研发,全称Yellowdog Update Modifier 是rhel系列系统上rpm包管理器的前端工具,可用来自动解决依赖关系,从而更好的实现程序包的安 ...
- linux编译curl库的动态库so(转)
转载请注明出处:帘卷西风的专栏(http://blog.csdn.NET/ljxfblog) curl库是一个很强大的http开源库,c++里面能够很方便的和http服务器交互. 最近项目开始内测,开 ...
- CSS颜色名称和颜色值
aliceblue:艾利斯兰 #F0F8FF antiquewhite:古董白 #FAEBD7 aqua:浅绿色 #00FFFF aquamarine:碧绿色 #7FFFD4 azure:天蓝色 #F ...
- TableView刷新指定的cell 或section
//一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:]; [tableview reloadSections:ind ...
- 基于PHP使用rabbitmq实现消息队列
1.从github上面获取AMQP基于php的实现扩展 2.创建生产者 send.php 3.创建消费者 receive.php 4.在cli模式下 分别执行 send.php receive. ...
- Windows server 2003 WINS的配置和使用详解
NetBios名称概述 网络中的一台计算机可以使用NETBIOS和DNS两种命名方式为其命名,在NETBIOS标准中,使用长度不超 过16个字符的名称来惟一标识每个网络资源,用于标识资源或服务类型.在 ...