Lunes, Pebrero 20, 2012

Shell Sort

Shellsort

From Wikipedia, the free encyclopedia
  (Redirected from Shell Sort)
Shellsort
Step-by-step visualisation of Shellsort
Shellsort with gaps 23, 10, 4, 1 in action.
Class Sorting algorithm
Data structure Array
Worst case performance depends on gap sequence
Best case performance O(N)
Average case performance depends on gap sequence
Worst case space complexity O(1)
Shellsort, also known as Shell sort or Shell's method is an in-place comparison sort. It generalizes an exchanging sort, such as insertion or bubble sort, by allowing the comparison and exchange of elements that lie far apart.[citation needed] Its first version was published by Donald Shell in 1959.[1][2] The running time of Shellsort is heavily dependent on the gap sequence it uses. For many practical variants, determining their time complexity remains an open problem.

[edit] Description

Shellsort is a multi-pass algorithm. Each pass is an insertion sort of the sequences consisting of every h-th element for a fixed gap h (also known as the increment). This is referred to as h-sorting.
An example run of Shellsort with gaps 5, 3 and 1 is shown below.
\begin{array}{rcccccccccccc}
    &a_1&a_2&a_3&a_4&a_5&a_6&a_7&a_8&a_9&a_{10}&a_{11}&a_{12}\\
  \hbox{input data:}
    & 62& 83& 18& 53& 07& 17& 95& 86& 47& 69& 25& 28\\
  \hbox{after 5-sorting:}
    & 17& 28& 18& 47& 07& 25& 83& 86& 53& 69& 62& 95\\
  \hbox{after 3-sorting:}
    & 17& 07& 18& 47& 28& 25& 69& 62& 53& 83& 86& 95\\
  \hbox{after 1-sorting:}
    & 07& 17& 18& 25& 28& 47& 53& 62& 69& 83& 86& 95\\
\end{array}

Walang komento:

Mag-post ng isang Komento