The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs

Shell sort algorithm is also known as Shell's method algorithm which is the variation of insertion sort algorithm. Shell sort algorithm is an improved form of insertion sort algorithm as it compares elements separated by a gap of several position. In Shell sort algorithm, the elements in an array are sorted in multiple passes and in each pass, data are taken with smaller and smaller gap sizes. However, the finale of shell sort algorithm is a plain insertion sort algorithm. But the time we reach the last part, the elements in an array are already sorted, thus Shell sort algorithm provides better performance.

- Shell sort algorithm is only efficient for finite number of elements in an array.
- Shell sort algorithm is 5.32 x faster than bubble sort algorithm.

- Shell sort algorithm is complex in structure and bit more difficult to understand.
- Shell sort algorithm is significantly slower than the merge sort, quick sort and heap sort algorithms.

Here is the program to demonstrate Shell Sort.

shell-sort.c

#include <stdio.h> int sort(); void display(); int x[100],n,i; int main() { printf("\n Enter the size of the array : "); scanf("%d",&n); printf("\n Enter %d elements in the array : \n",n); for(i=0; i < n; ++i) scanf("%d",&x[i]); sort(); display(); } void display() { printf("\nSorted Array in ascending order is : \n"); for(i=0; i < n; ++i) printf("%5d",x[i]); } int sort() { int temp, i ,h; for(h = 1; h < n/9; h=3*h+1); for(; h > 0; h/=3) { for(i = h; i < n; ++i) { int j; temp = x[i]; for(j = i-h; j >= 0; j-=h) { if(temp < x[j]) x[j+h] = x[j]; else break; } x[j+h] = temp; } } }

Enter the size of the array : 5 Enter 5 elements in the array : 4 3 1 2 5 Sorted Array in ascending order is : 1 2 3 4 5

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report

We to update you

© Copyright 2018