introsort
Sign in to saveAlso known as introspective sort
Introsort or introspective sort is a hybrid sorting algorithm that provides both fast average performance and (asymptotically) optimal worst-case performance. It begins with quicksort, it switches to heapsort when the recursion depth exceeds a level based on (the logarithm of) the number of elements being sorted and it switches to insertion sort when the number of elements is below some threshold. This combines the good parts of the three algorithms, with practical performance comparable to quicksort on typical data sets and worst-case O(n log n) runtime due to the heap sort. Since the three a
Key facts
- Algorithm.class
- Sorting algorithm
- Algorithm.data
- Array
- Algorithm.time
- O(n log n)
- Algorithm.average time
- O(n log n)
- Algorithm.optimal
- yes
via Wikipedia infobox
Wikidata facts
Show 2 more facts
- Stack Exchange tag
- stackoverflow.com/tags/introsort
- time of discovery or invention
- 1997-00-00
Sources (1)
via Wikidata · CC0
~5 min read
Article
8 sectionsContents
- Pseudocode
- Analysis
- Implementations
- Variants
- pdqsort
- fluxsort
- References
- General
Introsort or introspective sort is a hybrid sorting algorithm that provides both fast average performance and (asymptotically) optimal worst-case performance. It begins with quicksort, it switches to heapsort when the recursion depth exceeds a level based on (the logarithm of) the number of elements being sorted and it switches to insertion sort when the number of elements is below some threshold. This combines the good parts of the three algorithms, with practical performance comparable to quicksort on typical data sets and worst-case O(n log n) runtime due to the heap sort. Since the three algorithms it uses are comparison sorts, it is also a comparison sort.
Introsort was invented by David Musser in , in which he also introduced introselect, a hybrid selection algorithm based on quickselect (a variant of quicksort), which falls back to median of medians and thus provides worst-case linear complexity, which is optimal. Both algorithms were introduced with the purpose of providing generic algorithms for the C++ Standard Library which had both fast average performance and optimal worst-case performance, thus allowing the performance requirements to be tightened. Introsort is in-place and a non-stable algorithm.