Solved

Most efficient gap sequence for the shell sort

Posted on 2011-03-10
4
1,866 Views
Last Modified: 2012-05-11
Hi there, I've been experimenting with the shell sort and I seem to get the quickest sort times when I start the gap sequence at half the size of the sequence, and then divide it by 2.2 for each pass until its done. The thing is, I cannot find an explanation for why 2.2 seems to be the quickest. Does anyone have any insight on this?
0
Comment
Question by:terminal434
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:tygrus2
ID: 35107228
Have you tried differently ordered/random starting lists ? Describe the lists to be sorted: number of elements, mostly random or partially sequential with a tail ?

I had fun at school with a modified bubble sort that alternated running left and right (like Nightrider' car, KIT lights) and shrank the sort window  for already sorted slots (upper and lower bounds became closer together). I looked it up today and found something similar is can now be called the Cocktail sort. It's good with partially sorted lists but the worse case is no more than half n squared. Your shell sort should theoritically perform better.
0
 
LVL 18

Accepted Solution

by:
Jose Parrot earned 500 total points
ID: 35108530
Interesting your research and observations.
The subject is far to be closed in a definitive conclusion. By now, thanks to Marcin Ciura, the best gap sequence for Shell sort is
       1, 4, 10, 23, 57, 132, 301, 701, 1750
which is something similar to a geometric progression growth ("similar" because the factor isn't constant, varying around 2.2 and 2.5), as in Fig. 1.

Others sequences were found, like the series
       1, 5, 19, 41, 109, 209, 505, 929, 2161, 3905, 8929, 16001, 36289, 64769, 146305, 260609, 587521, 1045505, 2354689, 4188161, 9427969, 16764929, 37730305, 67084289, 150958081, 268386305, 603906049, 1073643521, 2415771649

Some one has suggested the Fibonacci numbers (this Italian is always around!) but the one from Ciura is assumed as the best until now.

Your number 2.2 can be a particular case, I'm not sure about, but seems to be.
You may want read the cited author, besides Robert Sedgewick and, of course, Donald Shell.
Sedgewick paper at http://www.cs.princeton.edu/~rs/shell/paperF.pdfhttp://www.cs.princeton.edu/~rs/shell/paperF.pdf
is probably a good reference for you.

Jose Shell sort best known sequence
0
 
LVL 18

Assisted Solution

by:Jose Parrot
Jose Parrot earned 500 total points
ID: 35134412
Althought your 2.2 factor seems an empyric number, it is easy to notice that how close to Ciura factors is! The best exlanation on that are, as far we know, in the cited papers. Not a single answer, but long articles.
Jose
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35134845
JoseParrot,
Could you please upload the pdf file here. When I use your link, the result is
Sorry, the page you requested couldn't be found.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
convert number to binary VB6 16 550
Calculate only first half of IFFT 6 138
Stanford NLP enhance splitting a line to sentences 10 378
wordsFront challenge 8 121
This algorithm (in C#) will resize any image down to a given size while maintaining the original aspect ratio. The maximum width and max height are both optional but if neither are given, the original image is returned. This example is designed t…
Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question