Prerequisites:Insertion Sort, Quick Sort, Selection Sort In this article, a Hybrid algorithm with the combination of quick sort and insertion sort is implemented. As the name suggests, the Hybrid algorithm combines more than one algorithm. Why Hybrid algorithm: Quicksort algorithm is efficient if the size of the input is very large. But, insertion sort is more efficient than quick sort in case of small arrays as the number of comparisons and swaps are less compared to quicksort. So we combine the two algorithms to sort efficiently using both approaches. Note:Selectionsort algorithm can also be used to combine with quicksort. Though the time complexity is of O(N2), these algorithms prove to be efficient in this case because these are used only when the size of the array is less than a threshold value(10 in this article).
Approach: The idea is to use recursion and continuously find the size of the array. If the size is greater than the threshold value(10), then the quicksort function is called for that portion of the array. Else, insertion sort is called. Below is the implementation of the Hybrid algorithm: