November 2008
Intermediate to advanced
208 pages
4h 32m
English
Shell sort is an insertion sorting algorithm: A value is stored to a temporary value, then inserted into its appropriate place. One difference between this algorithm and the traditional insertion sort is that a shell sort compares two elements that are separated by a gap of several positions—in essence, making bigger jumps. This slight change results in greater efficiency in the worst-case scenario. Remember, worst-case scenarios are when a list of elements are in complete disarray and cannot be disordered any more than they currently are.
require 'benchmark'
def shell_sort(a)
i = 0
j = 0
size = a.length
increment = size / 2
temp = 0
while increment > 0
i = increment
while i<size
j = i
temp = a[i] ...Read now
Unlock full access