Skip to main contentSkip to solution

The worst case time complexity of Insertion Sort is _______________.

Solution

✅ Correct Option: 1

Insertion Sort takes each element and shifts it left past every larger element before it. The worst case is a reverse-sorted array, where the ii-th element must move past all i−1i - 1 elements before it.

Total shifts =1+2+⋯+(n−1)=n(n−1)2=O(n2)= 1 + 2 + \dots + (n-1) = \dfrac{n(n-1)}{2} = \boxed{O(n^2)}


Option 2: nn is the best case, an already sorted array, where each element needs only one comparison.

Option 4: log⁡n\log n is the number of comparisons if binary search is used to find the position, but the shifting still takes O(n2)O(n^2).

Keyboard Shortcuts

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