SHELL SORT ALGORITHM
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
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
Example
Here these values are {35, 14}, {33, 19}, {42, 27} and {10, 44}
Example
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 −
Example
Then, take interval of 2 and this gap generates two sub-lists –
{14, 27, 35, 42}, {19, 10, 33, 44}
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.
Example
We see that it
required only four
swaps to sort the rest
of the array.
Empirical Analysis of Shell Sort
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
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.
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.

Shellshort ppt

  • 1.
  • 2.
    Shell Sort  Foundedby 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 ShellSort 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
  • 4.
    Example Here these valuesare {35, 14}, {33, 19}, {42, 27} and {10, 44}
  • 5.
    Example Compare values ineach sub-list and swap them (if necessary) in the original array. After this step, the new array should look like this −
  • 6.
    Example Then, take intervalof 2 and this gap generates two sub-lists – {14, 27, 35, 42}, {19, 10, 33, 44}
  • 7.
    Example Again, compare andswap 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 thatit required only four swaps to sort the rest of the array.
  • 9.
  • 10.
    Empirical Analysis ofShell 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 ofShell 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 BestCase  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.