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) 计数排序不是基于比较的排序算法,其核心在于将输入的数据值转化为键存储在额外开辟的数组空间中. 作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范 ...
随机推荐
- redis3.0.5集群部署安装详细步骤
Redis集群部署文档(centos6系统) (要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如下) ...
- jquery :checked(过滤选择器) 和 空格:checked(后代选择器)
jquery 过滤选择器 和 后代选择器 <%@ page language="java" contentType="text/html; charset=UTF- ...
- html 表格的制作
表格的制作 表格<table></table> <table width="" height="" align=" ...
- POJ 3352-Road Construction (图论-双边联通分支算法)
题目大意:一个图,要求你加入最少的边,使得最后得到的图为一个边双连通分支.所谓的边双连通分支,即不存在桥的连通分支(题目保证数据中任意两点都联通). 解题思路:先用tarjan算法进行缩点建立DAG图 ...
- 手机驱动无法正常安装,出现adb interface失败
手机一直无法用usb连接上电脑,试了各种方法,总是提示安装驱动失败,或者找不到文件. 在网上找了各种方法,后来结果证明,是我自己手贱了,... 方法: Win7系统用户已经碰到几次在安装adb驱动时提 ...
- Eclipse 反编译插件安装jad
Eclipse的反编译插件一直在用jad,感觉很不错. 刚下了个新版的eclipse,配置jad的时候发现要多设置个东西. 从头开始 环境介绍: eclipse version:Kepler Rele ...
- VS2005 “无法在证书存储区中找到清单签名证书”错误的解决方法
方法一:在VS2005中出现该错误时,用记事本打开项目的.csproj文件,删除以下内容即可: <ManifestCertificateThumbprint>B531F2CF2227 ...
- LeetCode(76) Minimum Window Substring
题目 Given a string S and a string T, find the minimum window in S which will contain all the characte ...
- EditText的hint不显示
EditText的hint不显示可能的原因: 1.字体颜色与EditText的背景色一样; 2.使用了android:inputType = phone; 3.如果加上android:ellipsiz ...
- jQuery最佳实践(转载)
本文转载于阮一峰的博文. 上周,我整理了<jQuery设计思想>. 那篇文章是一篇入门教程,从设计思想的角度,讲解“怎么使用jQuery”.今天的文章则是更进一步,讲解“如何用好jQuer ...