Properties of Merge Sort
Solution
| Algorithm | Best case | Worst case | Auxiliary space |
|---|---|---|---|
| Selection sort | |||
| Bubble sort | |||
| Insertion sort | |||
| Merge sort |
Solution
No. In place means auxiliary space. The merge step allocates a temporary array as large as the range it merges, up to elements, so merge sort uses auxiliary space. Writing the result back into arr does not change that.
Solution
No. On a tie the condition is false, so the merge takes the element from the right half first, ahead of an equal element that came earlier in the array. Changing < to <= makes it stable: a tie then takes from the left half, which holds the earlier elements, so equal elements keep their original order.
Solution
Insertion sort. On a nearly sorted array almost every key stops after one comparison, so it runs close to its best case. Merge sort does its full regardless of the order, and selection sort does its full . Bubble sort with early termination finishes an already-sorted array in , but a small element near the end moves left only one slot per pass, so it can still cost on a nearly sorted array.