GO-V.ORG
As seen in

introsort

Introsort or introspective sort is a hybrid sorting algorithm that provides both fast average performance and (asymptotically) optimal worst-case performance.[src] 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.[src] 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.[src] Since the three algorithms it uses are comparison sorts, it is also a comparison sort.[src] 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.[src] 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.[src] Introsort is in-place and a non-stable algorithm.[src]

Introsort or introspective sort is a hybrid sorting algorithm that provides both fast average performance and (asymptotically) optimal worst-case performance.[src] 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.[src] 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.[src] Since the three algorithms it uses are comparison sorts, it is also a comparison sort.[src] 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.[src] 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.[src] Introsort is in-place and a non-stable algorithm.[src] ==Pseudocode== If a heapsort implementation and partitioning functions of the type discussed in the quicksort article are available, the introsort can be described succinctly as procedure sort(A : array): maxdepth ← ⌊log 2 (length(A))⌋ × 2 introsort(A, maxdepth) procedure introsort(A, maxdepth): n ← length(A) if n 2 ) for contrived sequences.[src] The median-of-3 pivot selection algorithm takes the median of the first, middle, and last elements of the list; however, even though this performs well on many real-world inputs, it is still possible to contrive a median-of-3 killer list that will cause dramatic slowdown of a quicksort based on this pivot selection technique.[src] Musser reported that on a median-of-3 killer sequence of 100,000 elements, introsort's running time was 1/200 that of median-of-3 quicksort.[src] Musser also considered the effect on caches of Sedgewick's delayed small sorting, where small ranges are sorted at the end in a single pass of insertion sort.[src] He reported that it could double the number of cache misses, but that its performance with double-ended queues was significantly better and should be retained for template libraries, in part because the gain in other cases from doing the sorts immediately was not great.[src] ==Implementations== Introsort or some variant is used in a number of standard library sort functions, including some C++ sort implementations.[src] The June 2000 SGI C++ Standard Template Library stl_algo.h implementation of unstable sort uses the Musser introsort approach with the recursion depth to switch to heapsort passed as a parameter, median-of-3 pivot selection and the Knuth final insertion sort pass for partitions smaller than 16.[src] The GNU Standard C++ library is similar: uses introsort with a maximum depth of 2×log 2 n, followed by an insertion sort on partitions smaller than 16.[src] LLVM libc++ also uses introsort with a maximum depth of 2×log 2 n, however the size limit for insertion sort is different for different data types (30 if swaps are trivial, 6 otherwise).[src] Also, arrays with sizes up to 5 are handled separately.[src] Kutenin (2022) provides an overview for some changes made by LLVM, with a focus on the 2022 fix for quadraticness.[src] The Microsoft .NET Framework Class Library, starting from version 4.5 (2012), uses introsort instead of simple quicksort.[src] Go uses a modification of introsort: for slices of 12 or less elements it uses insertion sort, and for larger slices it uses pattern-defeating quicksort and more advanced median of three medians for pivot selection.[src] Prior to version 1.19 it used shell sort for small slices.[src] Java, starting from version 14 (2020), uses a hybrid sorting algorithm that uses merge sort for highly structured arrays (arrays that are composed of a small number of sorted subarrays) and introsort otherwise to sort arrays of ints, longs, floats and doubles.[src] ==References== ===General=== Niklaus Wirth.[src] Algorithms and Data Structures.[src] Prentice-Hall, Inc., 1985.[src] .[src]

33 sentences · 33 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"introsort." encyclopegia.org, 2025, https://encyclopegia.org/wiki/introsort. Accessed 06 December 2026.

Chicago

"introsort." encyclopegia.org. Accessed December 6, 2026. https://encyclopegia.org/wiki/introsort.

APA

encyclopegia.org. (2025). introsort. Retrieved December 6, 2026, from https://encyclopegia.org/wiki/introsort

Accessed December 6, 2026 · CC BY-SA 4.0 · citation page · JSON

CC BY-SA 4.0 · tier1-factual · https://en.wikipedia.org/w/index.php?oldid=1318479533 · 0.55 · snapshot introsort-162516-6a8a6821b14b3782 · QID Q1395653

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners
  • Index — every corpus, paper and record
  • Estate guide — what a public data estate is
  • Founder — Lois-Kleinner Alpasan
  • Records — DOIs and external deposits
  • Documents — one-pagers, PDFs and QR codes
  • Brand kit — logos and share images
  • Papers — plain-language briefs with citations
  • Browser — search engine, PWA and bookmarklet
  • Anticloud — the operator and its projects

As seen in Business Insider · 336 outlets · evidence DOIs · plain-language papers

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.