What is the time complexity of the merge-insertion sort algorithm?

Sorting Algorithms Questions Medium



80 Short 66 Medium 49 Long Answer Questions Question Index

What is the time complexity of the merge-insertion sort algorithm?

The time complexity of the merge-insertion sort algorithm is O(n log n).

In merge-insertion sort, the input list is divided into smaller sublists until each sublist contains only one element. Then, these sublists are merged back together using the merge operation, which combines two sorted sublists into a single sorted sublist.

The merge operation has a time complexity of O(n), where n is the total number of elements in the two sublists being merged. Since the merge operation is performed log n times (as the number of sublists is halved in each iteration), the overall time complexity of the merge step is O(n log n).

In the insertion step, each element from the merged sublist is inserted into its correct position in the final sorted list. The insertion operation has a time complexity of O(n) in the worst case, as it may need to shift all the elements to make room for the new element.

Since the insertion step is performed for each element in the merged sublist, the overall time complexity of the insertion step is also O(n log n).

Therefore, the time complexity of the merge-insertion sort algorithm is O(n log n).