Uploaded by Johnrey Nasayao

3-Shell-Sort

advertisement
SHELL SORT
Shell sort is a highly efficient sorting algorithm
and is based on insertion sort algorithm. This
algorithm avoids large shifts as in case of
insertion sort, if the smaller value is to the far
right and has to be moved to the far left.
 This algorithm uses insertion sort on a widely
spread elements, first to sort them and then
sorts the less widely spaced elements. This
spacing is termed as interval. This interval is
calculated based on Knuth's formula as


In shell sort, elements at a specific interval are
sorted. The interval between the elements is
gradually decreased based on the sequence
used. the performance of the shell sort
depends on the type of sequence used for a
given input array.
Some of the optimal sequences used are:
Shell’s original sequence: N/2 , N/4 , …, 1
 Knuth’s increments: 1, 4, 13, …, (3k – 1) / 2
 Sedgewick’s increments: 1, 8, 23, 77, 281, 1073,
4193, 16577...4j+1+ 3·2j+ 1.
 Hibbard’s increments: 1, 3, 7, 15, 31, 63, 127,
255, 511…
 Papernov & Stasevich increment: 1, 3, 5, 9, 17,
33, 65,...
 Pratt: 1, 2, 3, 4, 6, 9, 8, 12, 18, 27, 16, 24, 36,
54, 81....

The same process goes on for remaining elements.

This algorithm is quite efficient for mediumsized data sets as its average and worst-case
complexity of this algorithm depends on the
gap sequence the best known is Ο(n), where n
is the number of items. And the worst case
space complexity is O(n).
Download