Skip to main contentSkip to solution

Which of the following data list will be the worst case scenario for Insertion Sort?

Solution

✅ Correct Option: 2

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 n=5n = 5 this gives 1+2+3+4=101 + 2 + 3 + 4 = 10 shifts, which is n(n−1)2\dfrac{n(n-1)}{2} and so O(n2)O(n^2).


Option 1: already sorted, which is the best case. Each element needs only one comparison, giving O(n)O(n).

Options 3 and 4: nearly sorted lists, so very few shifts are needed (1 and 3 respectively), far from the maximum of 10.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question