Solved

Most efficient gap sequence for the shell sort

Posted on 2011-03-10
4
1,747 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
  • 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:
JoseParrot 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:JoseParrot
JoseParrot 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to sort list into time slots 4 138
Java string tokenizing help on Fantasy Football 6 102
cat dog challenge 18 124
scoresClump  challenge 31 139
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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