algorithm - shell排序的理解

标签 algorithm sorting shellsort

我有几个在网上找不到的关于 Shell 排序与 Shell 差距的问题。

public static void shell(int[] a) {
    int increment = a.length / 2;
    while (increment > 0) {
        for (int i = increment; i < a.length; i++) {
            int j = i;
            int temp = a[i];
            while (j >= increment && a[j - increment] > temp) {
                a[j] = a[j - increment];
                j = j - increment;
            }
            a[j] = temp;
        }
        if (increment == 2) {
            increment = 1;
        } else {
            increment *= (5.0 / 11);
        }
    }
}

这是网上找的代码,但是最后的else语句我不是很懂。 5.0/11代表什么? 我还需要分析算法的复杂性,尽管我收到的结果非常令人困惑:

results

似乎最好和最坏的情况都是 O(n)。这些结果是否合法?

最佳答案

5.0/11其实就是用来获取增量的一半。任何 <0.5 和 >0.45 的值都可以获得整数值的一半。

关于algorithm - shell排序的理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42988004/

相关文章:

java - Java 中的 Shell 排序算法变体

ruby - 递归解决方案没有正确迭代

c - C 中的 Shell 排序未给出所需结果

algorithm - 面试 - 根据开始和结束值排序

c++ - 确定 std::sort(begin, end) 是否修改了范围

php - 在PHP中对两个对应的数组进行排序

c++ - 对每个元素都是一对的 vector 元素进行排序

c - Shell 排序中的 h 排序

algorithm - 在面向消费者的应用程序中同步数据时如何处理冲突?

algorithm - 采用有向图并返回顶点数的线性时间算法