SortLab

Production hybrids · Advanced

Introsort

Start with Quicksort, switch to Heap Sort if recursion gets risky, and finish tiny ranges with insertion.

Best
O(n log n)
Average
O(n log n)
Worst
O(n log n)
Space
O(log n)
Stability
Not stable
Memory model
In-place

How it builds order

  1. Partition like Quicksort.
  2. Decrease the depth budget.
  3. Use Heap Sort when the budget reaches zero.
  4. Use Insertion Sort for tiny ranges.

Why it works

Quicksort supplies strong average behavior; the heap fallback caps the worst case; insertion reduces overhead on small ranges.

Watch for: The depth budget prevents repeatedly bad partitions from reaching quadratic time.

The interactive version of this page adds the full trace, synchronized pseudocode, practice decisions, input experiments, and mastery review.

Compare related strategies