Shell Sorting

Shell Sorting

Shell sort, also known as Shellsort, is a simple and effective sorting algorithm that repeatedly steps through the list and sort pair of items far apart from each other, then progressively reducing the gap between elements to be compared. By starting with far apart element, in general, it doesn't shift a vast amount of elements as in [Bubble Sorting](/go/algorithms/bubble-sorting/), which makes it more efficient

Shell Sorting algorithm (ascending) #

info Pseudocode for Shell Sorting algorithm (ascending)
ITERATE over gaps WHERE gap = N/2^k AND gap > 0
    ITERATE over list s STARTING from gap position
        ITARATE backwards by gap UNTIL j-gap >= 0
            IF s[j] < s[j-gap]
                SWITCH items

Sorted Array = s

&ldquo;Shell Sorting algorithm&rsquo;s visualization, ascending order&rdquo;

------ Execution ------

Shell Sorting (classic method)
list (before): [4 1 3 2]
list (after): [1 2 3 4]