Open In App

Hybrid Sorting Algorithms

Last Updated : 21 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Hybrid sorting algorithms combine two or more standard sorting techniques to optimize performance. For example, Insertion sort works well for small inputs and Quick Sort for large and IntroSort (A Hybrid Sorting Algorithm) uses these properties for using Quick Sort while the input is large and switch to insertion sort when the size becomes small. Hybrid algorithms are used more in real world (or standard library functions) of languages because of their flexibility to adjust according to input data.

Here are a few common hybrid sorting algorithms:

Timsort

  • It uses Merge Sort and Insertion Sort
  • It breaks the array into small runs and each run is sorted using Insertion Sort. Multiple runs are merged using Merge Sort.
  • It is a stable sorting
  • It is used in Python sort() and sorted()
  • Also used in Java' s Collections.sort library method.

IntroSort

  • It combines QuickSort, HeapSort, and Insertion Sort.
  • It begins with QuickSort, switches to HeapSort if recursion depth becomes too large (to avoid worst-case performance of QuickSort). For small arrays, Insertion Sort is used to finish the sorting.
  • It is not a stable sorting
  • It is used in C++'s standard library for std::sort()

Apart from above two algorithms, Dual-Pivot QuickSort is also used in libraries more frequently. For example, Java's Arrays.sort uses it for sorting arrays



Next Article
Article Tags :
Practice Tags :

Similar Reads