Complete the following table with the properties of the indicated sorts. (Note that an "in-place" sort is a sort that doesn't require any additional space beyond the space required to store the input.)
Worst-Case Comparisons | Worst-Case Assignments | Worst-Case Time | Best-Case Time | Average Time | In place? | Stable? | |
---|---|---|---|---|---|---|---|
Selection Sort | |||||||
Insertion Sort | |||||||
Mergesort | |||||||
Quicksort |
Choose the best sorting algorithm for each of the following scenarios. You should choose from among selection sort, insertion sort, quicksort, and mergesort. In each case, justify your answer.
Dr. Arugorizumu has recently submitted a paper claiming that he has developed a Θ(n) algorithm for within-two-sorting an array. He claims that, while the algorithm is not guaranteed to completely sort a sequence, it does guarantee that each key will end up no more than two positions away from its correct sorted location. Is this claim believable? Why or why not?
The current programming assignment involves an optimization of the Mergesort algorithm that switches to insertion sort for small arrays. Develop a recurrence relation describing the best-case number of comparisons required by this modified Mergesort where k is the threshold for switching. You should not assume that the input size is a power of 2.