Sunday, April 5, 2009

Shell sort

- was invented by Donald Shell in 1959. It improves upon bubble sort and insertion sort by moving out of order elements more than one position at a time. One implementation can be described as arranging the data sequence in a two-dimensional array and then sorting the columns of the array using insertion sort. Although this method is inefficient for large data sets, it is one of the fastest algorithms for sorting small numbers of elements (sets with fewer than 1000 or so elements). Another advantage of this algorithm is that it requires relatively small amounts of memory.

Run-time Complexity Analysis:
This is an effective in terms of the efficiency of the sorted list.

Codes:
input: an array a of length ninc ← round(n/2)
while inc > 0 do:
for i = inc .. n − 1 do:
temp ← a[i]
j ← i
while j ≥ inc and a[j − inc] > temp do:
a[j] ← a[j − inc]
j ← j − inc
a[j] ← temp
inc ← round(inc / 2.2)

Application: Sorting the numbers in a certain row.

Reference:http://en.wikipedia.org/wiki/Sorting_algorithm#Shell_sort

No comments:

Post a Comment