Open In App

Sorting by combining Insertion Sort and Merge Sort algorithms

Insertion sort: The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed at the correct position in the sorted part.
Advantages: Following are the advantages of insertion sort:

Merge sort: Merge Sort is a Divide and Conquer algorithm. It divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves.



Advantages: Following are the advantages of merge sort:

From the above two comparisons, the advantages of both the sorting algorithms can be combined, and the resulting algorithm will have time complexity O(N[K+log(N/K)]). Below is the derivation of the time complexity of this combined algorithm:
Let, no. of elements in the list = N
Divide:



Sorting:

Merging:

The total cost of the algorithm (insertion + merge) is:

If K = 1, then it is complete merge sort which is better in terms of time complexity
If K = N, then it is complete Insertion sort which is better in terms of space complexity

Article Tags :