algorithm-base/animation-simulation/数据结构和算法/希尔排序.md

107 lines
5.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

> **[tan45du_one](https://raw.githubusercontent.com/tan45du/tan45du.github.io/master/个人微信.15egrcgqd94w.jpg)** ,备注 github + 题目 + 问题 向我反馈
>
>
>
> <u>[****](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u> 两个平台同步,想要和题友一起刷题,互相监督的同学,可以在我的小屋点击<u>[**刷题小队**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u>进入。
### ** Shell's Sort**
Arrays.sort (),47使
****Diminishing Increment Sort 1 1
![](https://cdn.jsdelivr.net/gh/tan45du/bedphoto2@master/20210122/微信截图_20210127164642.3glch9g6oey0.png)
![](https://cdn.jsdelivr.net/gh/tan45du/photobed@master/2021031719420587.b27cu8pv3eo.png)
421
使
![](https://cdn.jsdelivr.net/gh/tan45du/test1@master/20210122/希尔排序.4vxwr7bkbjw0.gif)
****
```java
class Solution {
public int[] sortArray(int[] nums) {
int increment = nums.length;
//注意看结束条件
while (increment > 1) {
//这里可以自己设置
increment = increment / 2;
//根据增量分组
for (int i = 0; i < increment; ++i) {
//这快是不是有点面熟,回去看看咱们的插入排序
for (int j = i + increment; j < nums.length; j += increment) {
int temp = nums[j];
int k;
for (k = j - increment; k >= 0; k -= increment) {
if (temp < nums[k]) {
nums[k+increment] = nums[k];
continue;
}
break;
}
nums[k+increment] = temp;
}
}
}
return nums;
}
}
```
使
![](https://cdn.jsdelivr.net/gh/tan45du/bedphoto2@master/20210122/微信截图_20210127212901.62c3o3ss6pg0.png)
4 2 1
Sedgewick Hibbard
Sedgewick
151941109.
9*4^k - 9*2^
O(n^(4/3))
Hibbard
13715......
2 ^ k-1
O(n^(3/2))
1
****
O(n^(1.3-2)) O(n^2),
****
O(1),
****
![](https://cdn.jsdelivr.net/gh/tan45du/bedphoto2@master/20210122/微信截图_20210128083925.5v2s0w4ummk0.png)
4 2
![](https://cdn.jsdelivr.net/gh/tan45du/bedphoto2@master/20210122/微信截图_20210128084911.6tmdmz51m2c0.png)