Vous êtes sur la page 1sur 1

SHELL SORT

Shell sort is a sorting algorithm, devised by Donald Shell in 1959, that is a generalization of insertion sort, which exploits the fact that insertion sort works efficiently on input that is already almost sorted. It improves on insertion sort by allowing the comparison and exchange of elements that are far apart. The last step of Shell sort is a plain insertion sort, but by then, the array of data is guaranteed to be almost sorted. For example, consider a list of numbers like [13 14 94 33 82 25 59 94 65 23 45 27 73 25 39 10]. If we started with a step-size of 5, we could visualize this as breaking the list of numbers into a table with 5 columns. This would look like this:
13 14 94 33 82 25 59 94 65 23 45 27 73 25 39 10

We then sort each column, which gives us


10 14 73 25 23 13 27 94 33 39 25 59 94 65 82 45

When read back as a single list of numbers, we get [ 10 14 73 25 23 13 27 94 33 39 25 59 94 65 82 45 ]. Here, the 10 which was all the way at the end, has moved all the way to the beginning. This list is then again sorted using a 3-gap sort as shown below.
10 25 27 39 94 45 14 23 94 25 65 73 13 33 59 82

Which gives us
10 25 27 39 45 94 14 23 25 65 94 13 33 59 73 82

Vous aimerez peut-être aussi