AlgoScope

TimSort

AlgorithmadvancedSorting

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
run 0-4308112220325425961476819

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.

Open in the player →or start at step 2

What you will see

Runs are detected and marked; a run stack merges neighbours when its size invariants break.

How more sorts works →

Cost

BestO(n)
AverageO(n log n)
WorstO(n log n)
SpaceO(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.

Related

Taught by the same lesson

More Sorts covers these too, in the same run.