Talk:Algorithm Implementation/Sorting/Shell sort

Transwiki from Wikipedia
This page was created with content from the English Wikipedia article Shell sort.

Edit history
* (cur) (last) 18:51, 17 August 2006 Booyabazooka (Talk | contribs) (transwiki code to wikibooks) * (cur) (last) 07:59, 17 August 2006 Bluebot (Talk | contribs) (not a stub) * (cur) (last) 08:06, 21 July 2006 MCiura (Talk | contribs) m (→The Gap sequence) * (cur) (last) 09:43, 7 July 2006 65.93.16.184 (Talk) (→Shell sort in Haskell) * (cur) (last) 09:42, 7 July 2006 65.93.16.184 (Talk) (→Shell sort in Haskell) * (cur) (last) 16:44, 2 July 2006 Booyabazooka (Talk | contribs) (→The Gap sequence - swap table png with svg) * (cur) (last) 11:07, 19 June 2006 Deco (Talk | contribs) (Unlink gap insertion sort (see talk page), remove redundant sentence) * (cur) (last) 20:26, 18 June 2006 Deco (Talk | contribs) (→The Gap sequence - Prettier big O)   * (cur) (last) 20:23, 18 June 2006 Deco (Talk | contribs) (Fix inconsistency) * (cur) (last) 09:38, 12 June 2006 128.112.139.194 (Talk) (→The Gap sequence) * (cur) (last) 05:48, 12 June 2006 A5b (Talk | contribs) m (link to ru:~) * (cur) (last) 18:41, 31 May 2006 Deco (Talk | contribs) (My mistake, it was right) * (cur) (last) 18:09, 31 May 2006 Deco (Talk | contribs) (→Shell sort in C - Fix bug in C impl (pretty sure this is what was intended)) * (cur) (last) 17:20, 31 May 2006 Deco (Talk | contribs) m (→The Gap sequence - Image is tiny and illegible) * (cur) (last) 17:19, 31 May 2006 Deco (Talk | contribs) (Add reference) * (cur) (last) 17:16, 31 May 2006 Deco (Talk | contribs) (Shell sort is better in the worst case, not just the average case) * (cur) (last) 15:06, 28 May 2006 24.10.235.160 (Talk) (→The Gap sequence) * (cur) (last) 15:05, 28 May 2006 24.10.235.160 (Talk) (→The Gap sequence) * (cur) (last) 14:04, 26 May 2006 69.156.155.124 (Talk) (→Shell sort in Haskell - add spaces to join blocks) * (cur) (last) 12:59, 26 May 2006 200.17.202.52 (Talk) (→Shell sort in C)   * (cur) (last) 12:58, 26 May 2006 200.17.202.52 (Talk) (→Shell sort in C)    * (cur) (last) 16:16, 25 May 2006 200.82.48.6 (Talk) (→Shell sort in C)    * (cur) (last) 16:14, 25 May 2006 200.82.48.6 (Talk) (→Shell sort in C)    * (cur) (last) 16:13, 25 May 2006 200.82.48.6 (Talk) (→Shell sort in C)    * (cur) (last) 09:44, 23 May 2006 Bluebot (Talk | contribs) (Unicodifying using AWB) * (cur) (last) 04:37, 13 May 2006 83.154.85.211 (Talk) * (cur) (last) 19:03, 11 May 2006 Booyabazooka (Talk | contribs) (Category:Comparison sorts) * (cur) (last) 22:46, 10 May 2006 69.156.155.124 (Talk) (→Example Implementations) * (cur) (last) 17:53, 10 May 2006 69.156.155.124 (Talk) (→Shell sort in Haskell) * (cur) (last) 17:51, 10 May 2006 69.156.155.124 (Talk) (→Shell sort in Haskell) * (cur) (last) 17:50, 10 May 2006 69.156.155.124 (Talk) * (cur) (last) 01:44, 24 April 2006 68.169.41.238 (Talk) (mistake by previous editor) * (cur) (last) 00:50, 24 April 2006 128.211.201.44 (Talk) (→fixed swap in the for(j=i-gap..) loop) * (cur) (last) 00:40, 11 April 2006 203.167.156.163 (Talk) (→Example implementation in C)   * (cur) (last) 00:39, 11 April 2006 203.167.156.163 (Talk) (→Example implementation in C)    * (cur) (last) 16:01, 27 March 2006 MacsBug (Talk | contribs) m (Fixed typo) * (cur) (last) 21:21, 22 March 2006 Jwlee (Talk | contribs) (→External links - Last link is the same as the third one) * (cur) (last) 16:44, 11 March 2006 Sigmalmtd (Talk | contribs) (Added Gap sequence, References) * (cur) (last) 18:56, 8 March 2006 129.174.185.10 (Talk) (→External links) * (cur) (last) 17:26, 6 March 2006 Udo.bellack (Talk | contribs) m (links to bubble_sort, array) * (cur) (last) 18:00, 2 March 2006 138.86.177.203 (Talk) * (cur) (last) 05:44, 2 March 2006 MCiura (Talk | contribs) m (→Example implementation in C)   * (cur) (last) 22:05, 1 March 2006 71.114.239.187 (Talk) (→External links) * (cur) (last) 22:02, 1 March 2006 71.114.239.187 (Talk) * (cur) (last) 02:09, 14 February 2006 Damian Yerrick (Talk | contribs) (→Example implementation in C - The number of elements is NOT sizeof(gaps); it's sizeof(gaps)/sizeof(gaps[0]). Also fix the --j problem in shellSortPhase) * (cur) (last) 19:52, 13 February 2006 Donhalcon (Talk | contribs) m (→External links - (stub-sort)) * (cur) (last) 17:04, 11 February 2006 Sf222 (Talk | contribs) (→Example implementation in C - code correction (but check it please)) * (cur) (last) 00:37, 6 February 2006 Damian Yerrick (Talk | contribs) (→Example implementation in C - correct the for loop) * (cur) (last) 23:16, 5 February 2006 Damian Yerrick (Talk | contribs) (1. it's an insertion sort, not a bubble sort; 2. add a sample implementation; 3. cleanup text) * (cur) (last) 14:01, 2 February 2006 198.182.56.5 (Talk) * (cur) (last) 11:30, 31 December 2005 71.111.219.4 (Talk) * (cur) (last) 15:42, 23 December 2005 Deco (Talk | contribs) (Stub in wrong place) * (cur) (last) 14:52, 23 December 2005 CesarB (Talk | contribs) (restore external links/categories/interwiki) * (cur) (last) 14:50, 23 December 2005 CesarB (Talk | contribs) (Add copyvio source as external link) * (cur) (last) 14:28, 23 December 2005 CesarB (Talk | contribs) (reverting the copyvio turned the article into a stub; tagging as ) * (cur) (last) 14:28, 23 December 2005 CesarB (Talk | contribs) (clearing copyvio; copyvio was introduced via merge from shellsort on 2003-05-02; reverting to version of 2002-12-30) * (cur) (last) 13:57, 15 December 2005 Smack (Talk | contribs) * (cur) (last) 10:21, 9 December 2005 71.51.8.39 (Talk) (Add a reference to a sequence of Pratt and Hibbard) * (cur) (last) 09:10, 29 November 2005 210.176.196.210 (Talk) (→Analysis) * (cur) (last) 22:23, 28 November 2005 Deco (Talk | contribs) (Link comparison sort) * (cur) (last) 11:20, 15 November 2005 FlaBot (Talk | contribs) m (robot Adding: pl) * (cur) (last) 17:05, 2 October 2005 Fawcett5 (Talk | contribs) (→Analysis - dab Robert Sedgewick (computer scientist)) * (cur) (last) 18:31, 26 September 2005 Clemmy (Talk | contribs) (rv vandalism) * (cur) (last) 18:25, 26 September 2005 129.123.104.8 (Talk) (→Using Fibonacci numbers) * (cur) (last) 12:18, 31 August 2005 Bubba73 (Talk | contribs) (→Analysis - usually not...) * (cur) (last) 12:29, 30 August 2005 Paranoid (Talk | contribs) m (→Analysis) * (cur) (last) 12:28, 30 August 2005 Paranoid (Talk | contribs) (→Analysis - evolution) * (cur) (last) 19:03, 13 August 2005 M7bot (Talk | contribs) m (robot Adding: pt) * (cur) (last) 22:34, 15 July 2005 Bubba73 (Talk | contribs) (→Analysis - add Tokuda sequence of gaps) * (cur) (last) 13:50, 14 July 2005 RobotE (Talk | contribs) m (robot Modifying: lt) * (cur) (last) 23:00, 12 July 2005 Mathbot (Talk | contribs) (Robot-assisted spelling. See User:Mathbot/Logged misspellings for changes.) * (cur) (last) 01:59, 12 July 2005 Bubba73 (Talk | contribs) (→Analysis - links to sequences) * (cur) (last) 19:23, 11 July 2005 Bubba73 (Talk | contribs) (→Analysis - average cases for two sequences) * (cur) (last) 19:06, 11 July 2005 Bubba73 (Talk | contribs) m (→References - updated Knuth ref to 2nd edition, which has much more recent analysis, etc) * (cur) (last) 16:30, 25 June 2005 Mathbot (Talk | contribs) (Robot-assisted spelling. See User:Mathbot/Logged misspellings for changes.) * (cur) (last) 05:01, 25 June 2005 Pne (Talk | contribs) m (→Analysis - See also this entry in OEIS's sequences index for a list of sequences used in shell sorting.) * (cur) (last) 05:00, 25 June 2005 Pne (Talk | contribs) m (→Analysis - OEIS sequence number) * (cur) (last) 22:44, 13 June 2005 Enochlau (Talk | contribs) m (→Using fibonacci numbers) * (cur) (last) 05:29, 13 June 2005 Enochlau (Talk | contribs) m (→Using a list of shell sizes - readability of code) * (cur) (last) 08:03, 11 May 2005 Clemmy (Talk | contribs) (Revert to Revision as of 15:36, 9 May 2005; please use the sandbox or your user page to try out formatting.) * (cur) (last) 06:19, 11 May 2005 61.246.96.88 (Talk) (→Example) * (cur) (last) 10:36, 9 May 2005 80.178.225.28 (Talk) (→Using fibonacci numbers - deleted some smartarse comment left by a previous writer) * (cur) (last) 06:51, 9 May 2005 MCiura (Talk | contribs) m (→Analysis) * (cur) (last) 14:58, 2 May 2005 P3d0 (Talk | contribs) m (→Example - copy edit and wikify) * (cur) (last) 14:53, 2 May 2005 P3d0 (Talk | contribs) m (Link Marlene Metzner) * (cur) (last) 22:39, 30 April 2005 FlaBot (Talk | contribs) m (warnfile Modifying:es) * (cur) (last) 20:41, 13 April 2005 143.107.183.232 (Talk) (→Example) * (cur) (last) 13:22, 12 April 2005 221.124.106.12 (Talk) (→Example) * (cur) (last) 16:46, 11 April 2005 Dinoen (Talk | contribs) m (+it Interlink) * (cur) (last) 10:46, 1 April 2005 62.134.117.1 (Talk) (minor correction) * (cur) (last) 10:24, 1 April 2005 62.134.112.128 (Talk) (1. Optimized the Java code. 2. Recommended squares of Fibonacci numbers. 3. Deleted the slow, obscure C code. (Better port the Java code to C! 2 trivial changes in line 1 and 3 only: move the [].)) * (cur) (last) 21:37, 29 March 2005 Clemmy (Talk | contribs) m (grammar, style) * (cur) (last) 06:48, 21 March 2005 Knutux (Talk | contribs) m (interwiki: +lt) * (cur) (last) 00:59, 8 March 2005 Daniel Quinlan (Talk | contribs) m (don't link Creative Computing) * (cur) (last) 00:59, 8 March 2005 Daniel Quinlan (Talk | contribs) m (don't link Creative Computing) * (cur) (last) 23:37, 7 March 2005 Daniel Quinlan (Talk | contribs) * (cur) (last) 17:16, 1 January 2005 LiDaobing (Talk | contribs) m   * (cur) (last) 18:35, 31 December 2004 Kevin Mulligan (Talk | contribs) (Reverted blanking by anon user) * (cur) (last) 18:33, 31 December 2004 130.113.219.244 (Talk) * (cur) (last) 10:41, 17 December 2004 193.0.83.59 (Talk) (Added reference/bibitem to D.E. Knuth 'Sorting and Searching'. Should references be in alphabetical order?) * (cur) (last) 10:21, 17 December 2004 193.0.83.59 (Talk) (→Analysis) * (cur) (last) 05:35, 15 December 2004 80.58.22.44 (Talk) (→Using a list of shell sizes in C Edit By Z80user) * (cur) (last) 03:42, 15 December 2004 80.58.22.42 (Talk) (→Using a list of shell sizes in C Edit By Z80user) * (cur) (last) 04:56, 14 December 2004 Jdforrester (Talk | contribs) m (Reverted edits by 213.139.47.29 to last version by 80.58.22.42) * (cur) (last) 04:54, 14 December 2004 213.139.47.29 (Talk) (→Implementations) * (cur) (last) 17:02, 4 December 2004 80.58.22.42 (Talk) * (cur) (last) 20:04, 26 November 2004 217.251.190.24 (Talk) (added V. Pratt as inventor of the first h-sequence) * (cur) (last) 17:39, 24 November 2004 Oberiko (Talk | contribs) m (Reverted edits by 204.62.200.25 to last version by Damian Yerrick) * (cur) (last) 17:38, 24 November 2004 204.62.200.25 (Talk) (→Implementations) * (cur) (last) 17:36, 24 November 2004 204.62.200.25 (Talk) (→Using fibonacci numbers) * (cur) (last) 23:41, 20 November 2004 Damian Yerrick (Talk | contribs) (→Analysis - Clarify what is the worst case; does anybody have the Big O value for Knuth's sequence?) * (cur) (last) 09:48, 30 October 2004 145.254.166.2 (Talk) (linkified intra-page reference) * (cur) (last) 09:15, 21 October 2004 Robbot (Talk | contribs) m (robot Adding:es) * (cur) (last) 02:27, 5 October 2004 Mark T (Talk | contribs) (Sedgewick sequence; rewording of Fibonacci sequence) * (cur) (last) 02:20, 5 October 2004 Mark T (Talk | contribs) (Sedgewick sequence; rewording of Fibonacci sequence) * (cur) (last) 16:10, 3 August 2004 66.203.175.179 (Talk) (Removed "penis" from article text. (Very funny.)) * (cur) (last) 10:40, 3 August 2004 140.247.244.244 (Talk) (→Basic concept) * (cur) (last) 13:21, 31 July 2004 Carribeiro (Talk | contribs) m (→My Favourite - Fixed a link to the golden ratio entry) * (cur) (last) 22:43, 1 July 2004 Maximus Rex (Talk | contribs) m   * (cur) (last) 10:24, 30 June 2004 137.18.255.35 (Talk) (→Analysis) * (cur) (last) 11:36, 15 June 2004 82.116.73.17 (Talk) (added link to "Fibonacci number") * (cur) (last) 11:26, 15 June 2004 82.116.73.17 (Talk) (Changed consistent misspelling 'fibbonachi' to 'fibonacci) * (cur) (last) 23:09, 10 June 2004 203.10.231.231 (Talk) (→Implementations) * (cur) (last) 23:08, 10 June 2004 203.10.231.231 (Talk) (→Implementations) * (cur) (last) 23:03, 10 June 2004 203.10.231.231 (Talk) (Golden Ratio) * (cur) (last) 10:11, 30 May 2004 Timwi (Talk | contribs) (Category:Sort algorithms) * (cur) (last) 10:52, 15 May 2004 Puckly (Talk | contribs) m (whoops) * (cur) (last) 10:51, 15 May 2004 Puckly (Talk | contribs) m (+nl:) * (cur) (last) 00:05, 8 May 2004 Jaredwf (Talk | contribs) m   * (cur) (last) 23:02, 11 April 2004 Dysprosia (Talk | contribs) m (fix [[o)    * (cur) (last) 23:01, 11 April 2004 Dysprosia (Talk | contribs) m (whoops, fix pip)    * (cur) (last) 23:01, 11 April 2004 Dysprosia (Talk | contribs) (no, that's Java. C does not say int[] a, it says int a[])    * (cur) (last) 22:57, 11 April 2004 Dmercer (Talk | contribs) m (=Implementations= Sample sort is written in C, not Java.)    * (cur) (last) 16:33, 29 February 2004 Deco (Talk | contribs) m (Fixed external links)    * (cur) (last) 16:33, 29 February 2004 Deco (Talk | contribs) (Oops, removed duplicated sections)    * (cur) (last) 16:32, 29 February 2004 Deco (Talk | contribs) (Sectioned, made code less tall, minor editing, added link)    * (cur) (last) 17:51, 20 February 2004 213.157.5.169 (Talk) (de)    * (cur) (last) 14:01, 15 February 2004 Timwi (Talk | contribs) m    * (cur) (last) 18:00, 21 January 2004 AlexPlank (Talk | contribs) (of the oldest sorting algorithms. It was invented in 1959 by Donald L. Shell [Sh].)    * (cur) (last) 08:23, 31 October 2003 Dysprosia (Talk | contribs) m (no, this is java, arrays are declared like that in java)    * (cur) (last) 08:21, 31 October 2003 Dysprosia (Talk | contribs) m (fix fmt)    * (cur) (last) 08:18, 31 October 2003 203.200.40.199 (Talk) (The person who submitted failed to compile the program, it is full of compile errors, array declarations of []a and []cols is changed, added semicolon at the end of cols initialization - Manik Raina)    * (cur) (last) 09:02, 9 August 2003 219.98.152.107 (Talk) (+ja)    * (cur) (last) 04:35, 24 July 2003 68.100.96.143 (Talk)    * (cur) (last) 03:03, 9 May 2003 Hephaestos (Talk | contribs) m    * (cur) (last) 13:12, 2 May 2003 Hephaestos (Talk | contribs) (moved info from old Shellsort)    * (cur) (last) 03:14, 2 May 2003 217.1.45.137 (Talk)    * (cur) (last) 03:13, 2 May 2003 217.1.45.137 (Talk)    * (cur) (last) 13:43, 30 December 2002 24.112.162.82 (Talk) m (Its/it's typo)    * (cur) (last) 05:37, 21 December 2002 Maveric149 (Talk | contribs) m (bold and wiki)    * (cur) (last) 19:38, 18 December 2002 Graue (Talk | contribs) m (Helpful links added, exponent fixed)    * (cur) (last) 16:22, 3 November 2002 128.8.80.69 (Talk)    * (cur) (last) 16:22, 3 November 2002 128.8.80.69 (Talk)    * (cur) (last) 01:59, 29 August 2002 211.28.96.44 (Talk)

Algorithm question
First of all i think that instead of: for (j = i - gap; j >= 0 && a[j] > value; --j) there should be for (j = i - gap; j >= 0 && a[j] > value; j-=gap)

The code still yelds the correct result beacause in the final step gap=1 and the alg does an insert sort.... But in terms of complexity it won't act well

Secondly i think the algorithm should also be explained in words, most of the time this helps a lot... A similar explanation like the one in the first link of the external links section would be great. I will insert it if you guys don't mind.
 * I agree with your second point. However, your first point is incorrect; if we were to move j by gap, we would only sort one column of the matrix containing the list rearranged into gap columns, so the sort would not be effective. This is crucial. Deco 00:34, 19 June 2006 (UTC)