2. Shell Sort
Founded by Donald Shell in 1959
1st algorithm to break the quadratic time barrier
a highly efficient sorting algorithm
known as diminishing increment sort
Generalization of insertion short
3. How does Shell Sort Works?
works by comparing elements that are distant rather than
adjacent elements in an array or list where adjacent elements are
compared
uses increment sequence
makes multiple passes through a list
improves on the efficiency of insertion sort
decreases distance between comparisons
7. Example
Again, compare and swap the values, if required, in the original array.
After this step, the array should look like this −
Finally, the rest of the array sorted using interval of value 1. Shell
sort uses insertion sort to sort the array.
8. Example
We see that it
required only four
swaps to sort the rest
of the array.
10. Empirical Analysis of Shell Sort
(Advantage)
Fastest of all O (N^2) sorting algorithms
it’s only efficient for medium size lists
Five (5) times faster than the bubble sort
a little over twice as fast as the insertion sort
11. Empirical Analysis of Shell Sort
(Dis-advantage)
it is a complex algorithm
it’s not nearly as efficient as the merge, heap, and quick sorts
still significantly slower than the merge, heap, and quick sorts
also an excellent choice for repetitive sorting of smaller lists.
12. Shell Sort Best Case
when the array is already sorted in the right order
the number of comparisons is less.
Shell Sort Worst Case
running time of Shell sort depends on the choice of increment
sequence.
pairs of increments are not necessarily relatively prime and smaller
increments can have little effect.