You have to sort a list L. consisting of a sorted list followed by a few 'random' elements. Which of the following sorting method would be most suitable for…
You have to sort a list L. consisting of a sorted list followed by a few 'random' elements. Which of the following sorting method would be most suitable for such a task?
Show answerHide answer
Correct answer: (D) Insertion sort
Explanation
For a sorted list followed by a few random elements: bubble sort and selection sort take O(n²) time, quick sort degrades to its O(n²) worst case on nearly sorted input, while insertion sort takes close to O(n) time. Hence insertion sort is most suitable.