Question
Which sorting algorithm is not in-place in its standard form?
A.Bubble sort
B.Insertion sort
C.Selection sort
D.Merge sort
Correct Answer: D. Merge sort
Detailed textbook explanation
Step-by-step solution
An in-place algorithm sorts using only a constant amount of extra memory, O(1), rearranging elements within the given array.
Bubble sort, insertion sort and selection sort all swap elements within the original array and need only a few temporary variables, so they are in-place.
Standard merge sort splits the array and merges sorted halves into a separate temporary array of size proportional to the input, requiring O(n) extra space; hence it is not in-place in its standard form.
Key takeaway
Merge sort's merge step needs an auxiliary array of size O(n), so standard merge sort is out-of-place.
Common mistake
Assuming merge sort is in-place because it is a comparison sort — extra memory use, not the comparison method, decides in-place status.