原文地址:http://www.stoimen.com/blog/,在此感谢作者!

Insertion sort is a great algorithm, because it’s very intuitive and it is easy to implement, but the problem
is that it makes many exchanges for each “light” element in order to put it on the right place. Thus
“light” elements at the end of the list may slow down the performance of insertion sort a lot. That is why
in 1959 Donald Shell proposed an algorithm that tries to overcome this problem by comparing items of
the list that lie far apart.

How to choose gap size
Not a cool thing about Shell sort is that we’ve to choose “the perfect” gap sequence for our list. However
this is not an easy task, because it depends a lot of the input data. The good news is that there are some
gap sequences proved to be working well in the general cases.

Shell Sequence
Donald Shell proposes a sequence that follows the formula FLOOR(N/2 ), then for N = 1000, we get the
following sequence: [500, 250, 125, 62, 31, 15, 7, 3, 1]

Pratt Sequence
Pratt proposes another sequence that’s growing with a slower pace than the Shell’s sequence. He
proposes successive numbers of the form (2^q)* (3^q) or [1, 2, 3, 4, 6, 8, 9, 12, …].

Knuth Sequence
Knuth in other hand proposes his own sequence following the formula (3^k – 1) / 2 or [1, 4, 14, 40, 121, …]

Complexity
Yet again we can’t determine the exact complexity of this algorithm, because it depends on the gap
sequence. However we may say what is the complexity of Shell sort with the sequences of Knuth, Pratt
and Donald Shell. For the Shell’s sequence the complexity is O(n*n ), while for the Pratt’s sequence it is
O(n*log (n)). The best approach is the Knuth sequence where the complexity is O(n^(3/2) ), as you can see
on the diagram bellow.

Application
Well, as insertion sort and bubble sort, Shell sort is not very effective compared to quicksort or merge
sort. The good thing is that it is quite easy to implement (not easier than insertion sort), but in general it
should be avoided for large data sets. Perhaps the main advantage of Shell sort is that the list can be
sorted for a gap greater than 1 and thus making less exchanges than insertion sort.

希尔排序( Shell Sort)的更多相关文章

  1. [算法] 希尔排序 Shell Sort

    希尔排序(Shell Sort)是插入排序的一种,它是针对直接插入排序算法的改进.该方法又称缩小增量排序,因DL.Shell于1959年提出而得名. 希尔排序实质上是一种分组插入方法.它的基本思想是: ...

  2. 排序算法--希尔排序(Shell Sort)_C#程序实现

    排序算法--希尔排序(Shell Sort)_C#程序实现 排序(Sort)是计算机程序设计中的一种重要操作,也是日常生活中经常遇到的问题.例如,字典中的单词是以字母的顺序排列,否则,使用起来非常困难 ...

  3. 希尔排序Shell sort

    希尔排序Shell Sort是基于插入排序的一种改进,同样分成两部分, 第一部分,希尔排序介绍 第二部分,如何选取关键字,选取关键字是希尔排序的关键 第一块希尔排序介绍 准备待排数组[6 2 4 1 ...

  4. 希尔排序——Shell Sort

    前言: 数据序列1: 13-17-20-42-28 利用插入排序,13-17-20-28-42. Number of swap:1;数据序列2: 13-17-20-42-14 利用插入排序,13-14 ...

  5. 排序之希尔排序(shell sort)

    前言 本篇博客是在伍迷兄的博客基础上进行的,其博客地址点击就可以进去,里面好博客很多,我的排序算法都来自于此:一些数据结构方面的概念我就不多阐述了,伍迷兄的博客中都有详细讲解,而我写这些博客只是记录自 ...

  6. Python排序算法——希尔排序(Shell’s Sort)

    有趣的事,Python永远不会缺席! 如需转发,请注明出处:小婷儿的python https://www.cnblogs.com/xxtalhr/p/10793487.html 一.希尔排序(Shel ...

  7. 数据结构 - 希尔排序(Shell's Sort) 具体解释 及 代码(C++)

    数据结构 - 希尔排序(Shell's Sort) 具体解释 及 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy/article/details/2 ...

  8. 希尔排序(Shell)

    希尔排序的实质就是分组插入排序,该方法又称缩小增量排序. 该方法的基本思想是:先将整个待排元素序列分割成若干个子序列(由相隔某个“增量”的元素组成的)分别进行直接插入排序,然后依次缩减增量再进行排序, ...

  9. 希尔排序(shell)理论---不含源码

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 希尔排序,是一个缩小增量排序.它根据步长来进行排序,步长不同可能会产生不同的序列,但是他们的最终结果是相同的,希尔排序的官方理论难以理解, ...

随机推荐

  1. Activity启动模式 及 Intent Flags 与 栈 的关联分析

     http://blog.csdn.net/vipzjyno1/article/details/25463457    Android启动模式Flags栈Task   目录(?)[+] 什么是栈 栈 ...

  2. MyEclipse------快速写入内容到指定目录下的文件(字节输出流)

    other.jsp <%@ page language="java" import="java.util.*" pageEncoding="UT ...

  3. MyEclipse------遍历某个路径下的(所有或特定)文件和目录

    usebean包(自己定义的,在src文件夹下面)里的java文件 FileAccept.java package usebean; import java.io.File; import java. ...

  4. linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)

     linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...

  5. linux4

    linux 特点:1.免费 开源(代码公开)2.支持多线程/多用户的操作系统3.安全性4.对内存和文件管理有自己的一套优越的方法 linux最小只需要4M ->嵌入式开发默认不启动用户界面roo ...

  6. Java基础—ClassLoader的理解

    ##默认的三个类加载器 Java默认是有三个ClassLoader,按层次关系从上到下依次是: - Bootstrap ClassLoader - Ext ClassLoader - System C ...

  7. 机器学习公开课笔记(4):神经网络(Neural Network)——表示

    动机(Motivation) 对于非线性分类问题,如果用多元线性回归进行分类,需要构造许多高次项,导致特征特多学习参数过多,从而复杂度太高. 神经网络(Neural Network) 一个简单的神经网 ...

  8. Swift Tour 随笔总结 (4)

    Switch的一个例子: let vegetable = "red pepper" switch vegetable { case "celery": let ...

  9. 用 VeraCrypt 加密闪存盘

    导读 很多安全专家偏好像 VeraCrypt 这类能够用来加密闪存盘的开源软件,是因为可以获取到它的源代码.要是你需要在 Windows 系统,苹果的 OS X 系统或者 Linux 系统上加密以及访 ...

  10. ZeroMQ(java)中组件间数据传输(Pipe的实现)

    在ZeroMQ(java)中,整个IO的处理流程都是分层来进行的,当然处于最下端的肯定是前面介绍过的poller以及StreamEngin了....涉及到上层的话就还有session,以及socket ...