Introsort(内省排序)是一种混合排序算法:通常先使用快速排序(Quicksort),在递归深度过大、可能退化为最坏情况时,自动切换为堆排序(Heapsort)以保证时间复杂度;并常在小规模子数组上使用插入排序(Insertion sort)提升常数效率。它常见于许多语言/库的通用排序实现(如 C++ 的 std::sort)。
Introsort is fast in practice and avoids quicksort’s worst-case slowdown.
Introsort 在实践中很快,并能避免快速排序在最坏情况下的性能骤降。
Many standard libraries implement their default sort using introsort, switching to heapsort when recursion gets too deep.
许多标准库用内省排序实现默认排序:当递归过深时会切换到堆排序。
/ˈɪntrəˌsɔːrt/
Introsort 是 introspective sort(“内省的排序”)的缩写/合成词:*intro-*(向内、内省)+ sort(排序)。含义是算法会“自我检查”运行状态(如递归深度),在检测到可能变慢时改变策略。该算法由 David R. Musser 在 1990 年代提出并推广。
std::sort 及其实现策略时常提及 introsort。 std::sort)时常与 introsort 关联。