当前位置:网站首页>Shell Sort
Shell Sort
2022-07-05 05:09:00 【ximen502_】
The content of this paper comes from Data structure Textbook (C Language version )
Shell Sort (Shell’s Sort), Also known as reducing incremental sorting (Diminishing Increment Sort), It is also a method of insertion sort , But in terms of time efficiency, it is much better than the previous insertion sorting .
its The basic idea yes : First, divide the whole record sequence to be sorted into several subsequences , separately , Direct insert sort , When the records in the whole sequence are basically in order , Do a direct insertion sort for all records again .
The above picture description is too ambiguous , Hard to understand , The detailed decomposition diagram is as follows :
Sort using increment ( Stepping ) One time for 5, 3, 1, The first round of use 5 For stepping , From the subscript 0 Start backward with the subscript (0+5) Compare the numbers at , Small numbers go forward ( left ), Big numbers go backwards ( On the right side ), Then the subscript is 1 Start , by 2 Start , Step backward in turn until there is no step for 5 The second number of , Then the first round of sorting is completed .
Let's take the first round as an example to analyze in detail :
- First step
- The second step
- The third step
- Step four
- Step five
The above is the detailed process of the first round of sorting , The second round , The third round just changed the step , The basic idea has not changed .
Hill sort algorithm uses Java The implementation is as follows
/** * Specific sorting process * @param arr * @param dk The incremental */
void shellInsert(int[] arr, int dk) {
// An array arr Make a hill insertion sort .
for (int i = dk; i < arr.length; i++) {
if (arr[i] <= arr[i - dk]) {
int temp = arr[i];
int j = 0;
for (j = i - dk; j >= 0 && temp <= arr[j]; j -= dk) {
arr[j + dk] = arr[j];
}
arr[j + dk] = temp;
}
}
}// Shell Insert
void ShellSort(int[] arr, int[] dlta, int t) {
// Sequence by increment dlta[0..t-1] For the sequence table arr Make Hill sort
for (int i = 0; i < t; i++) {
shellInsert(arr, dlta[i]);
}
}
@Test
public void fun1() {
int[] arr = {
49, 38, 65, 97, 76, 13, 27, 49, 55, 04 };
int[] dlta = {
5, 3, 1 };
ShellSort(arr, dlta, dlta.length);
System.out.println(Arrays.toString(arr));
}
The analysis of Hill sort is a complex problem , Because its time is a function of the sequence quantity taken , This involves some unsolved mathematical problems .( The printing time of the textbook 2009 year 2 month , The time of publication is 2007 year , This year, 2019 year , It's about past publication 12 year , I wonder if these mathematical problems have been solved over the years .) The rest is like : Local conclusions drawn from a large number of studies , Taking incremental sequence , Let's read the textbook , There's a lot of content .
边栏推荐
- AutoCAD - Center zoom
- cocos2dx_ Lua card flip
- mysql審計日志歸檔
- 3dsmax snaps to frozen objects
- AutoCAD - graphic input and output
- Grail layout and double wing layout
- Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
- Create a pyGame window with a blue background
- 中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
- AutoCAD - full screen display
猜你喜欢
"Measuring curve length" of CAD dream drawing
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
BUUCTF MISC
Optimization scheme of win10 virtual machine cluster
PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低
Page countdown
Rip notes [rip three timers, the role of horizontal segmentation, rip automatic summary, and the role of network]
Leetcode word search (backtracking method)
Simple modal box
小程序直播+电商,想做新零售电商就用它吧!
随机推荐
China polyurethane rigid foam Market Research and investment forecast report (2022 Edition)
54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●
AutoCAD -- dimension break
Vs2015 secret key
How much do you know about 3DMAX rendering skills and HDRI light sources? Dry goods sharing
AutoCAD - set layer
Lua determines whether the current time is the time of the day
C语言杂谈1
AutoCAD - Zoom previous
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
Do a small pressure test with JMeter tool
小程序直播+电商,想做新零售电商就用它吧!
2022/7/2 question summary
When will Wei Lai, who has been watched by public opinion, start to "build high-rise buildings" again?
C iterator
cocos_ Lua loads the file generated by bmfont fnt
Unity intelligent NPC production -- pre judgment walking (method 1)
Judge the position of the monster in the role under unity3d
Optimization scheme of win10 virtual machine cluster
BUUCTF MISC