Introsort
Partition large ranges around a pivot, then switch methods when a range needs different treatment.
Start with a budget of twice the integer part of log₂(n). Each child inherits one less than its parent.
This version uses the last element as the pivot. Ranges of up to four keys use insertion. A larger range with no budget left uses a heap.
Worst-case time is O(n log n), with O(log n) stack space. Equal keys can change order.