Which of the following data list will be the worst case scenario for Insertion Sort?
Which of the following data list will be the worst case scenario for Insertion Sort?
Solution
Insertion sort takes the most time when every element must be shifted past all the elements before it. This happens when the list is in reverse (descending) order, as in [5, 4, 3, 2, 1].
Here each new element is smaller than everything already sorted, so it moves all the way to the front. For this gives shifts, which is and so .
Option 1: already sorted, which is the best case. Each element needs only one comparison, giving .
Options 3 and 4: nearly sorted lists, so very few shifts are needed (1 and 3 respectively), far from the maximum of 10.
Related questions:
2026: 31 May Shift 1
2025: 13 May Shift 2
2025: 16 May Shift 1