









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Shellsort makes multiple passes through a list and sorts a number of equally sized sets using the insertion sort.
Shellsort improves on the efficiency of insertion sort by quickly shifting values to their destination.
After each phase and some increment h k , for every i , we have a[ i ] ≤ a [ i + h k ] all elements spaced h k apart are sorted. The file is said to be h k
Source: http://linux.wku.edu/~lamonml/algor/sort/shell.html
Best Case: The best case in the shell sort is when the array is already sorted in the right order. The number of comparisons is less.
Sort: 18 32 12 5 38 33 16 2 8 Numbers to be sorted, Shell’s increment will be floor(n/2) *** floor(8/2)** floor(4) = 4 increment 4: 1 2 3 4 18 32 12 5 38 33 16 2 (visualize underlining) Step 1 ) Only look at 18 and 38 and sort in order ; 18 and 38 stays at its current position because they are in order. Step 2 ) Only look at 32 and 33 and sort in order ; 32 and 33 stays at its current position because they are in order. Step 3 ) Only look at 12 and 16 and sort in order ; 12 and 16 stays at its current position because they are in order. Step 4 ) Only look at 5 and 2 and sort in order ; 2 and 5 need to be switched to be in order.
Shellsort Examples (con’t) Sort: 18 32 12 5 38 33 16 2 Resulting numbers after increment 4 pass: 18 32 12 2 38 33 16 5 *** floor(4/2)** floor(2) = 2 increment 2: 1 2 18 32 12 2 38 33 16 5 Step 1 ) Look at 18 , 12 , 38 , 16 and sort them in their appropriate location: 12 38 16 2 18 33 38 5 Step 2 ) Look at 32 , 2 , 33 , 5 and sort them in their appropriate location: 12 2 16 5 18 32 38 33