Shell sort is a sorting algorithm that divides an array into smaller segments and sorts each segment using insertion sort. It works by first sorting elements that are far apart from each other and progressively reducing the gap between elements to sort until it reaches a gap of 1, at which point the array is fully sorted. While faster than bubble and insertion sort for medium sized lists, shell sort is slower than merge, heap, and quick sort algorithms. It is best suited for sorting smaller lists of less than 5000 items unless speed is critical.
Shell sort is a sorting algorithm that divides an array into smaller segments and sorts each segment using insertion sort. It works by first sorting elements that are far apart from each other and progressively reducing the gap between elements to sort until it reaches a gap of 1, at which point the array is fully sorted. While faster than bubble and insertion sort for medium sized lists, shell sort is slower than merge, heap, and quick sort algorithms. It is best suited for sorting smaller lists of less than 5000 items unless speed is critical.
Shell sort is a sorting algorithm that divides an array into smaller segments and sorts each segment using insertion sort. It works by first sorting elements that are far apart from each other and progressively reducing the gap between elements to sort until it reaches a gap of 1, at which point the array is fully sorted. While faster than bubble and insertion sort for medium sized lists, shell sort is slower than merge, heap, and quick sort algorithms. It is best suited for sorting smaller lists of less than 5000 items unless speed is critical.
contiguous segments • The distance between successive elements in one segment is called a gap. • Each segment is sorted within itself using insertion sort. • Continue until only one segment (gap = 1) - final sort finishes array sorting. Advantages of Shell Sort
• 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. Disadvantages of Shell Sort
• It is a complex algorithm and its not
nearly as efficient as the merge, heap, and quick sorts. • The shell sort is still significantly slower than the merge, heap, and quick sorts, 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 Best Case Scenario
• The best case in the shell sort is when the
array is already sorted in the right order. The number of comparisons is less Worst Case Scenario
• The running time of Shellsort depends
on the choice of increment sequence. The problem with Shell’s increments is that pairs of increments are not necessarily relatively prime and smaller increments can have little effect Let us consider the following example to have an idea of how 9 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} 10 Pseudo Code public static void shellSort(int[] a) { for (int gap = a.length / 2; gap > 0; gap /= 2) { for (int i = gap; i < a.length; i++) { // slide element i back by gap indexes // until it's "in order" int temp = a[i]; int j = i; while (j >= gap && temp < a[j - gap]) { a[j] = a[j – gap]; j -= gap; } a[j] = temp; } } }