当前位置:网站首页>Sort 5-count sort
Sort 5-count sort
2022-07-28 16:31:00 【World_ living】
Catalog
Preface

One 、 Count sorting
thought : Counting sorting is also called pigeon nest principle , It is an application of the deformation of hash table direct addressing method . Operation steps :
- Count the number of identical elements
- According to the statistical results, the sequence is recycled into the original sequence
Absolute mapping :
details :
(1): When the maximum value in the array is large , And the minimum value in the array is also large , So we open up B Space , There will be a lot of waste .
So relative mapping comes :
Code :( Several details should be handled carefully )
void CountSort(int* a,int n)
{
// Select the maximum value , minimum value
int i = 0,min = a[0],max = a[0];
for(i = 0;i < n;i++)
{
if(a[i] > max)
max = a[i];
if(a[i] < min)
min = a[i];
}
int range = max - min + 1;
int* count = (int*)malloc(sizeof(int) * range);
memset(count,0,sizeof(int) * range);
// Count
for(i = 0;i < n;i++)
{
count[a[i] -min]++;
}
int j = 0;
// Sort
for(i = 0;i < range;i++)
{
while(count[i]--)
{
a[j++] = i + min;
}
}
}
summary :
- Count sort can only be used for integer sort
- The efficiency of counting sorting in data range set is high , Limited application scenarios
- Time complexity :O(N~range)
- Spatial complexity :O(range)
- stability : Stable
See you next time .
边栏推荐
猜你喜欢

flashfxp 530 User cannot log in. ftp

使用js直传oss阿里云存储文件,解决大文件上传服务器限制

About standard IO buffers

ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境

Redis系列4:高可用之Sentinel(哨兵模式)

视频号找到金钥匙,抖音模仿后来人

Stm32cube infrared remote control: input capture

队列的介绍与实现(详解)

Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi

Why do most people who learn programming go to Shenzhen and Beijing?
随机推荐
“蔚来杯“2022牛客暑期多校训练营3 ACFHJ
PHP mb_ Substr Chinese garbled code
“蔚来杯“2022牛客暑期多校训练营3 H.Hacker SAM+线段树/DP/分治(不带修查区间最大子段和)
解决电脑恶意广告弹窗的思路
ANSA二次开发 - 抽中面的两种方法
Detailed explanation of QT qstring
Deeply understand the fusing configuration of istio traffic management
R language uses ggpairs function of ggally package to visualize pairwise relationship graph of grouping multivariable, set alpha parameter to change image transparency, diagonal continuous variable de
关于web对接针式打印机问题,Lodop使用
Zhaoqi science and technology innovation and entrepreneurship competition talent introduction platform, mass entrepreneurship and entrepreneurship competition high-level talent introduction
Qt学习之Qt Designer(设计师)
HyperMesh运行脚本文件的几种方法
ANSA二次开发 - 在PyCharm上搭建ANSA/META二次开发环境
正大杯黑客马拉松数据解析竞赛
mysql 查看事件状态语句和修改办法
信号屏蔽与处理
1. Simple command line connection to database
LabVIEW Linx toolkit controls Arduino equipment (expansion-1)
laravel
优化Hypermesh脚本性能的几点建议