希尔排序( Shell Sort)
原文地址: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)的更多相关文章
- [算法] 希尔排序 Shell Sort
希尔排序(Shell Sort)是插入排序的一种,它是针对直接插入排序算法的改进.该方法又称缩小增量排序,因DL.Shell于1959年提出而得名. 希尔排序实质上是一种分组插入方法.它的基本思想是: ...
- 排序算法--希尔排序(Shell Sort)_C#程序实现
排序算法--希尔排序(Shell Sort)_C#程序实现 排序(Sort)是计算机程序设计中的一种重要操作,也是日常生活中经常遇到的问题.例如,字典中的单词是以字母的顺序排列,否则,使用起来非常困难 ...
- 希尔排序Shell sort
希尔排序Shell Sort是基于插入排序的一种改进,同样分成两部分, 第一部分,希尔排序介绍 第二部分,如何选取关键字,选取关键字是希尔排序的关键 第一块希尔排序介绍 准备待排数组[6 2 4 1 ...
- 希尔排序——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 ...
- 排序之希尔排序(shell sort)
前言 本篇博客是在伍迷兄的博客基础上进行的,其博客地址点击就可以进去,里面好博客很多,我的排序算法都来自于此:一些数据结构方面的概念我就不多阐述了,伍迷兄的博客中都有详细讲解,而我写这些博客只是记录自 ...
- Python排序算法——希尔排序(Shell’s Sort)
有趣的事,Python永远不会缺席! 如需转发,请注明出处:小婷儿的python https://www.cnblogs.com/xxtalhr/p/10793487.html 一.希尔排序(Shel ...
- 数据结构 - 希尔排序(Shell's Sort) 具体解释 及 代码(C++)
数据结构 - 希尔排序(Shell's Sort) 具体解释 及 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy/article/details/2 ...
- 希尔排序(Shell)
希尔排序的实质就是分组插入排序,该方法又称缩小增量排序. 该方法的基本思想是:先将整个待排元素序列分割成若干个子序列(由相隔某个“增量”的元素组成的)分别进行直接插入排序,然后依次缩减增量再进行排序, ...
- 希尔排序(shell)理论---不含源码
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 希尔排序,是一个缩小增量排序.它根据步长来进行排序,步长不同可能会产生不同的序列,但是他们的最终结果是相同的,希尔排序的官方理论难以理解, ...
随机推荐
- [IOS UICollectionView模版]
创建CollectionCell模版: 1.新建类CollectionCell继承自UICollectionViewCell 2.新建Xib,命名为CollectionCell.xib a.选中Col ...
- Android Studio学习笔记
转:http://stormzhang.com/devtools/2014/11/25/android-studio-tutorial1 背景 相信大家对Android Studio已经不陌生了,An ...
- 项目总结—jQuery EasyUI- DataGrid使用
http://blog.csdn.net/zwk626542417/article/details/18839349 概要 jQuery EasyUI是一个基于jquery的集成了各种用户界面的框架, ...
- C#实现自动升级(附源码)
http://blog.csdn.net/zhuweisky/article/details/50439386 OAUS
- Matalab IFS分形算法
IFS 算法代码 function IFS_draw(M,p) N=; :length(p); eval(['a',num2str(k),'=reshape(M(',num2str(k),',:),2 ...
- C# 获取时间差(几天前,几小时前,几分钟前,几秒前)
#region 获取时间差string GetTime(BsonString getTime) /// <summary> /// 获取时间差 /// </summary> / ...
- chown命令
改变一个文件的所有者和组 1.命令格式: chown [选项]... [所有者][:[组]] 文件... 例子: komiles@iUbuntu:~/study/wordpress$ lltotal ...
- Card(bestcoder #26 B)
Card Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- Unity中下载和本地保存实例
原地址:http://www.linuxidc.com/Linux/2011-10/45888.htm Download.cs using UnityEngine; using System.Coll ...
- 变色龙安装程序 Chameleon Install 2.2 svn 2281发布
变色龙安装程序 Chameleon Install 2.2 svn 2281发布 1.更好的支持10.9 Mavericks2.更新ATi.nVidia显卡支持列表3.添加新的 CPU Model I ...