2. What is Shell sort?
• Shellsort, also known as Shell sort or Shell's method, is an in-
place comparison sort.
• Shell sort is a generalization of insertion sort that allows the exchange of items
that are far apart.
• The method starts by sorting pairs of elements far apart from each other, then
progressively reducing the gap between elements to be compared.
3. What is Shell sort?
• Starting with far apart elements, it can move some out-of-place elements into
position faster than a simple nearest neighbor exchange.
• Shell sort makes multiple passes through a list and sorts a number of equally
sized sets using the insertion sort.
4. Application
• Shell sort performs more operations and has higher cache miss
ratio than quicksort.
• However, since it can be implemented using little code and does not use the call
stack, some implementations of the qsort function in the C Standard
Library targeted at embedded System use it instead of quicksort.
• Shell sort can also serve as a sub-algorithm of introspective sort, to sort short
subarrays and to prevent a slowdown when the recursion depth exceeds a given
limit.
5. Advantages
• Advantage of Shell sort is that its only efficient for medium size lists. For bigger
lists, the algorithm is not the best choice. Fastest of all O(N^2) sorting
algorithms.
• 5 times faster than the bubble sort and a little over twice as fast as the insertion
sort, its closes competitor.
6. Disadvantage
• Disadvantage of Shell sort is that it is a complex algorithm and it’s not nearly as
efficient as the merge, heap, and quick sorts.
• The Shell sort is still significantly slower than the merge, heap, and quick sort,
but its relatively simple algorithm makes it a good choice for sorting lists of less
than 5000 items unless speed important.
• It’s also an excellent choice for repetitive sorting of smaller lists.
7. Shell sort Best Case
• The best case in the Shell sort is when the array is already sorted in the right
order. The number of comparisons is less.
8. Shell sort Worse Case
• The running time of Shell sort depends on the choice of increment sequence.
• The problem with Shell’s increment is that pairs of increments are not
necessarily relatively prime and smaller increment can have little effect.
10. Shell sort step-by-step guide
Let us consider the following example to have an idea of how shell sort works.
For our example and ease of understanding, we take the interval of 4. Make a
virtual sub-list of all values located at the interval of 4 positions. Here these values
are {35, 14}, {33, 19}, {42, 27} and {10, 44}
11. Shell sort step-by-step guide
We compare values in each sub-list and swap them (if necessary) in the
original array. After this step, the new array should look like this
Then, we take interval of 2 and this gap generates two sub-lists - {14, 19, 27, 41},
{35, 33, 42, 44}
12. Shell sort step-by-step guide
We compare and swap the values, if required, in the original array. After this step,
the array should look like this
13. Shell sort step-by-step guide
Finally, we sort the rest of the array using interval of value 1. Shell sort
uses insertion sort to sort the array.
Following is the step-by-step depiction