Professional Documents
Culture Documents
Then, we take an interval of 2 and will compare the elements with gap 2
• We compare and swap the values, if required, in the original array. After this step, the array should look like
this –
• Finally, we sort the rest of the array using an interval of value 1. Shell sort uses insertion sort to sort the array.
While insertion sort works by incrementing its elements by 1, shell sort uses the parameter gap
to divide the array into sub-arrays whose elements are “gap” apart. Then we can sort the individual list using insertion sort to obtain
the complete sorted array.
Shell sort performs faster than insertion sort and takes fewer moves to sort the array when compared to insertion sort.