TimSort
Find natural ascending runs, extend short ones by insertion sort, then merge neighbouring runs.
Decision · step 2 of 33More Sorts: Timsort finds two natural runs
From index 0 the values keep rising for 5 slots: a natural run of length 5. That is at least 4, so it is taken as it is.
What you will see
Runs are detected and marked; a run stack merges neighbours when its size invariants break.
Cost
| Best | O(n) |
|---|---|
| Average | O(n log n) |
| Worst | O(n log n) |
| Space | O(n) |
Properties
- ✓ comparison based
- ✓ stable
- × in place
- ✓ adaptive
- × online
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, compare two runs.
Screen readers: Cells announce index, value and state (comparing, swapped, sorted); each step announces the comparison outcome and any move.
Reduced motion: Swaps become value crossfades with outline flashes; sorted-region growth is a static span change.
Before this
Related
Taught by the same lesson
More Sorts covers these too, in the same run.