Shell Sort - Algorithm Introduction

This section describes the Shell Sort algorithm - A complex and fast sorting algorithm that repeatedly divides the entire collection into sub-collections by taking every h-th element for a fixed gap h and performs an insertion sort each sub-collection.

Shell Sort is a complex and fast sorting algorithm that repeatedly divides the entire collection into sub-collections by taking every h-th element for a fixed gap h and performs an insertion sort each sub-collection. The Quicksort algorithm was published by Donald Shell in 1959.

The basic idea of Shell Sort algorithm can be described as these steps:

1. Set a step size h that is smaller than the number of elements to be sorted, and greater that 1.

2. Group the entire collection of data elements in h groups by putting elements that are h steps away from each other into the same group.

3. Sort each group by exchanging locations of elements in the same group.

4. Repeat step 2 and 3 with a smaller step size h until h becomes 1.

This idea of sorting is based on the following facts:

• Sorting h groups of n/h elements in each group takes much less time than sorting n elements.
• If a collection is sorted with a step size h, it is called partially sorted, because any elements will be at most n-h steps away from it's final sorted position.
• If a collection is sorted with a step size h, the insertion sort will be much more efficient than the original collection.
• Insertion sort method should be used for each sorting step.
• The performance of this sorting method is strongly depending on the selection of grouping step sizes used in the sorting steps. One of the popular methods of selecting the grouping step sizes is to use this sequence: h(n+1) = 3*h(n) + 1.

Last update: 2011.