VOOZH about

URL: https://www.geeksforgeeks.org/dsa/advanced-quick-sort-hybrid-algorithm/

⇱ Advanced Quick Sort (Hybrid Algorithm) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Advanced Quick Sort (Hybrid Algorithm)

Last Updated : 12 Jul, 2025

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). 
 


Dry run of the algorithm: 
 

Let arr[] = {24, 97, 40, 67, 88, 85, 15, 66, 53, 44, 26, 48, 16, 52, 45, 23, 90, 18, 49, 80}
 

👁 Example pictorial explanation
Example explanation


 


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: 
 


Output
15, 16, 18, 23, 23, 24, 26, 40, 44, 45, 48, 49, 52, 53, 66, 67, 80, 85, 88, 90, 97, 

Time Complexity: O(N^2)
Auxiliary Space: O(N)

Comment
Article Tags:
Article Tags: