In insertion sort, if we are given to sort a list of n elements, then how many comparisons will be required?
In insertion sort, if we are given to sort a list of n elements, then how many comparisons will be required?
Solution
Insertion sort takes each element and compares it with the sorted part on its left, so the count depends on the input order. The number of comparisons is of order in the best case and of order in the worst case, so both Option 1 and Option 2 are accepted.
Best case (already sorted list): each of the elements needs just one comparison, so the total is .
Worst case (reverse-sorted list): the -th element is compared with all elements before it.
Option 3: no case of insertion sort needs comparisons; the maximum is about .
Option 4: comparisons is the cost of one binary search, not of sorting the whole list. Even binary insertion sort needs about comparisons in total.
Related questions:
2025: 21 May Shift 1
2026: 19 May Shift 1
2026: 24 May Shift 1
2026: 26 May Shift 1