Difference between revisions 15825660 and 15969320 on enwiki'''Shell sort''' (or '''Shellsort''') is one of the oldest [[sorting algorithm|sorting algorithms]]. It was invented in 1959 by [[D. L. Shell|Donald L. Shell]] <nowiki>[</nowiki>[[#References|Sh]]<nowiki>]</nowiki>. It is fast, easy to understand and easy to implement. However, its complexity analysis is a little more sophisticated. (contracted; show full) j = j - h; } a[j] = v; } } }</pre> === Using fFibonacci numbers === <pre> void shellsort (int[] a, int n) { int h = 1, hh = 1; while(hh < n) { // eg, h = 5, hh = 8 hh = hh + h; // hh = 8 + 5 = 13 h = hh - h; // h = 13 - 5 = 8 } while(hh > 1) { for (int i = h; i < n; i++) { int v = a[i]; int j = i; while (j >= h && a[j - h] > v) { a[j] = a[j - h]; j = j - h; } a[j] = v; } // eg.g., h = 8, hh = 13 h = hh - h; // h = 13 - 8 = 5 hh = hh - h; // hh = 13 - 5 = 8 } }</pre> The squares of Fibonacci numbers (1, 4, 9, 25, ...) make an even better sequence. ==References== [Kn] D.E. Knuth: Sorting and Searching, vol. 3 of The Art of Computer Programming. Addison-Wesley (1973)<br> [Se] R. Sedgewick: Algorithms. Addison-Wesley (1988)<br> [Sh] D.L. Shell: A high-speed sorting procedure. Communications of the ACM 2 (7), 30-32 (1959) == External links == *[http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/shell/shellen.htm Detailed analysis of Shell sort] * [http://www.nist.gov/dads/HTML/shellsort.html Dictionary of Algorithms and Data Structures: Shellsort] [[Category:Sort algorithms]] [[de:Shellsort]] [[es:Ordenación Shell Sort]] [[it:Shell sort]] [[lt:Kevalo rūšiavimo algoritmas]] [[nl:Shellsort]] [[ja:シェルソート]] [[zh:希尔排序]] All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://en.wikipedia.org/w/index.php?diff=prev&oldid=15969320.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|