Shell sort is a in-place comparison sort method to sort the element. Unlike other sorting methods in this method we start by sorting elements that are far apart or at fixed gap from each other and after every iteration we get partially sorted sublists.
Let us consider an array of 7 elements and sort them by gap of 3.
In the above example we see that as we have an array we compare element that are 3 gaps away so we sort the sublists (a0, a3, a6) , (a1, a4) , (a2, a5) .
The sorting of these sublists can be done using any method for my program I have used Insertion sort.
After every iteration we decrease the gap unitl we reach the gap of one where it simply compares the adjacent elements. Chosing the values of gaps is very important as has effects on the complexity of the sorting.
To know more about Shell sort click Here.
You might also be interested in
Bubble Sort
Insertion Sort
Selection sort
Hashing with Linear Probing
Hashing with Quadratic Probing
Double Hashing
Let us consider an array of 7 elements and sort them by gap of 3.
In the above example we see that as we have an array we compare element that are 3 gaps away so we sort the sublists (a0, a3, a6) , (a1, a4) , (a2, a5) .
The sorting of these sublists can be done using any method for my program I have used Insertion sort.
After every iteration we decrease the gap unitl we reach the gap of one where it simply compares the adjacent elements. Chosing the values of gaps is very important as has effects on the complexity of the sorting.
To know more about Shell sort click Here.
C Program
C++ Program
Sample input and output to check the program
You might also be interested in
Bubble Sort
Insertion Sort
Selection sort
Hashing with Linear Probing
Hashing with Quadratic Probing
Double Hashing
Comments
Post a Comment