Inmathematics andcomputer science, thesorting numbers are a sequence of numbers introduced in 1950 byHugo Steinhaus for the analysis ofcomparison sort algorithms. These numbers give theworst-case number of comparisons used by bothbinary insertion sort andmerge sort. However, there are otheralgorithms that use fewer comparisons.
Theth sorting number is given by the formula[1]
The sequence of numbers given by this formula (starting with) is
The same sequence of numbers can also be obtained from therecurrence relation[2],
It is an example of a2-regular sequence.[2]
Asymptotically, the value of theth sorting number fluctuates between approximately and depending on the ratio between and the nearestpower of two.[1]
In 1950,Hugo Steinhaus observed that these numbers count the number of comparisons used bybinary insertion sort, and conjectured (incorrectly) that they give the minimum number of comparisons needed to sort items using anycomparison sort. The conjecture was disproved in 1959 byL. R. Ford Jr. andSelmer M. Johnson, who found a different sorting algorithm, the Ford–Johnsonmerge-insertion sort, using fewer comparisons.[1]
The same sequence of sorting numbers also gives theworst-case number of comparisons used bymerge sort to sort items.[2]
The sorting numbers (shifted by one position) also give the sizes of the shortest possiblesuperpatterns for thelayered permutations.[3]