On Generating Worst-Cases for the Insertion Sort Julie Tillison* and Ching-KuangShene*t Department of Mathematics and Computer Science Northern Michigan University Marquette, MI 49855-5340 e-mail: {Jtilliso, shene}@nmu.edu ni can vary T in the range of O(n) and O(n2). For example, if n~ = ~/i, then we have T = e Introduction Many CS1 texts, for example Nance [2], and data structures and algorithms texts, for example Baase [1] and Sedgewick [3], use insertion sort as an example of elementary sorting algorithms that require O(n 2) comparisons to sort n data items. A worst case that forces the insertion sort to take O(n 2) comparisons is usually mentioned. This worst case, in general, is the reversed-order sequence of the sorted one, and the number of comparisons required is n(n - 1)/2. It is not difficult to show that n(n-1)/2 is the upper bound of all worst cases. On the other hand, the minimum number of comparisons required to sort n data items with insertion sort is n - 1, and in fact this is a tight lower bound. Knowing these facts, one may easily raise the following questions: (1) are there other non-trivial worst case input sequences? and (2) are
/lp/association-for-computing-machinery/on-generating-worst-cases-for-the-insertion-sort-MkOUVM0mS0