What is the time complexity of insertion sort in worst case?
What is the time complexity of insertion sort in worst case?
Solution
✅ Correct Option: 4
In the worst case the array is in reverse order. Each new element must be compared with, and shifted past, every element already sorted before it.
The -th element needs shifts, so the total is:
Option 3: is the best case, when the array is already sorted and each element needs only one comparison.
Option 2: is the worst case of merge sort and heap sort, not insertion sort.
Related questions:
2026: 31 May Shift 1
2026: 20 May Shift 1
2025: 22 May Shift 1