1 / 7

Shellsort

Shellsort. improved insertion sort. Shellsort. insertion sort: -most moves of data are a single step shellsort: -long moves in first loop, then shorter moves in later loops -uses same basic logic as insertion. Insertion pseudocode. a: array of integers, length n for (i = 1; i < n; i++)

honora
Download Presentation

Shellsort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Shellsort improved insertion sort

  2. Shellsort • insertion sort:-most moves of data are a single step • shellsort:-long moves in first loop, then shorter moves in later loops-uses same basic logic as insertion

  3. Insertion pseudocode a: array of integers, length n for (i = 1; i < n; i++) temp = a[i] j = i while ( a[j-1] > temp ) a[j] = a[j-1] j-- a[j] = temp 30 temp 33 39 42 43 14 16 21 27 33 39 42 43 30 32 11 56 26 19 42 10

  4. Shellsort • many small ‘parallel’ insertion sorts • reduce number of parallel sorts, round by round • last round is pure insertion sort (but data is ‘almost’ sorted)

  5. Shellsort pseudocode // h is “step size” h = 1 while ( h <= n ) h = h*3 + 1 while ( h > 1 ) h = h / 3 for (i = h; i < n; i++) temp = a[i] j = i while ( j >= h && a[j-h] > temp ) a[j] = a[j-h] j = j-h a[j] = temp

  6. Shellsort example A S O R T I N G E X A M P L E 13 h A E O R T I N G E X A M P L S 4 h A E A G E I N M P L O R T X S 1 h A A E E G I L M N O P R S T X

  7. Shellsort performance • formal analysis unsolved (as far as I know) • estimates: O(n3/2), possibly better • depends on sequence of h values – should be relatively prime

More Related