Skip to main contentSkip to solution

Insertion sort will have a time complexity of _______________in the worst case.

Solution

✅ Correct Option: 4

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.

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


Option 3: nn is the best case, when the array is already sorted and each element needs just one comparison.

Keyboard Shortcuts

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